php artisan make:controller NameOfTheController --plainssh [email protected] -p 2222php artisan make:controller NameOfTheController --plainssh [email protected] -p 2222php artisan make:model ModelNameDon't forget to specify which table this model refers to
class Product extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'tablename';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['title', 'description'];
}php artisan tinkerFrom this point on the commands are tinker commands
$item = new namespace\ModelName;
$item->fieldname = 'value';$item->toArray();or just
$item;It should return true.
$item->save()namespace\ModelName::all()->toArray();$item = namespace\ModelName::find(1234);$item = namespace\ModelName::where('fieldname', 'value');$item = namespace\ModelName::where('fieldname', 'value')->get();Don't forget you can only assign fields specified in ModelClass->$fillable.
$item = namespace\ModelName::create(['fieldname1' => 'value1', 'fieldname2' => 'value2']);Don't forget you can only assign fields specified in ModelClass->$fillable.
$item->update(['fieldname' => 'value']);This action will populate DB defined in .env with the migrations in database/migrations (ie execute all the up functions).
php artisan migrateThis action will perform all the down functions from the migrations in database/migrations.
php artisan migrate:resetThis action will go back in time to previous migration.
php artisan migrate:rollbackphp artisan make:migration add_tablename_table --create="tablename"php artisan make:migration add_columnname_to_tablename_table --table="tablename"In this case make sure the down function of the migration remove the column from the table.
public function down()
{
Schema::table('tablename', function (Blueprint $table) {
$table->dropColumn('columnname');
});
}