Hi guys,
This code fragment Homestead in the works , but it does not work Laragon.
Database manual gives an error occurs if you laravel :
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'admin.permissions' doesn't exist (SQL: select * from permissions)
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateRolePermissions extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function(Blueprint $table){
$table->increments('id');
$table->string('name');
$table->string('label');
$table->timestamps();
});
Schema::create('permissions', function(Blueprint $table){
$table->increments('id');
$table->string('name');
$table->string('label');
$table->timestamps();
});
Schema::create('permission_role', function(Blueprint $table){
$table->integer('role_id')->unsigined();
$table->integer('permission_id')->unsigined();
$table->foreign('role_id')
->referance('id')
->on('roles')
->onDelete('cascade');
$table->foreign('permission_id')
->referance('id')
->on('permissions')
->onDelete('cascade');
$table->primary(['role_id', 'permission_id']);
});
Schema::create('role_user', function(Blueprint $table){
$table->integer('role_id')->unsigined();
$table->integer('user_id')->unsigined();
$table->foreign('role_id')
->referance('id')
->on('roles')
->onDelete('cascade');
$table->foreign('user_id')
->referance('id')
->on('users')
->onDelete('cascade');
$table->primary(['role_id', 'user_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
\DB::statement('SET FOREIGN_KEY_CHECKS = 0');
Schema::drop('roles');
Schema::drop('permissions');
Schema::drop('permission_role');
Schema::drop('role_user');
\DB::statement('SET FOREIGN_KEY_CHECKS = 1');
}
}