php artisan migrate:fresh
Si se quiere que además ejecute los seeders:
php artisan migrate:fresh --seed
php artisan migrate:fresh
php artisan migrate:fresh --seed
Schema::create('permisos', function (Blueprint $table) {
$table->id();
$table->string('nombre', 50);
$table->string('slug',50);
$table->timestamps();
});
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('nombre', 50);
$table->string('slug',50);
$table->timestamps();
});
Schema::create('permisos_roles', function (Blueprint $table) {
$table->unsignedBigInteger('permisos_id');
$table->foreign('permisos_id','fk_permisorol_permiso')->references('id')->on('permisos')
->onDelete('cascade')
->onUpdate('restrict');
$table->unsignedBigInteger('roles_id');
$table->foreign('roles_id','fk_permisorol_rol')->references('id')->on('roles')
->onDelete('cascade')
->onUpdate('restrict');
$table->timestamps();
});
php artisan make:model Cliente --migration
php artisan make:migration create_usuarios_table
php artisan make:migration crear_usuarios_tabla --create=usuarios // para q te cree los metodos up y down
php artisan migrate
// rollback: deshace la última migración y elimina las tablas nuevas q se hayan creado en esa migración
php artisan migrate:rollback
// reset: deshace todas las migraciones (un rollback de todas)
php artisan migrate:reset
// refresh: borra todas las migraciones hechas y vuelve a ejecutarlas todas otra vez, con ello se pierden los datos no la estructura
php artisan migrate:refresh
// status: te indica si hay alguna migración q todavía no se haya ejecutado:
php artisan migrate:status
Por ejemplo si queremos modificar un campo por ejemplo de integer a decimal sería:
...
$table->decimal("precio");
...
una vez guardado el cambio hacer:
php artisan migrate:rollback
php artisan migrate
php artisan make:seeder ProfessionSeeder
public function run() {
$idProf = Profession::where('title', 'Profesión Dos')->value('id');
User::create([
'name' => 'uno',
'email' => 'uno2@gmail.com',
'password' => bcrypt('1234'),
'profession_id' => $idProf
]);
}
php artisan migrate:fresh --seed
php artisan migrate
php artisan db:seed
php artisan db:seed --class=UsersTableSeeder
En app\Providers\AppServiceProvider.php:
public function boot() {
Schema::defaultStringLength(191);
}