<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePermissionsAndRolesTables extends Migration
{
/**
@return void
*/
public function up()
{
Schema::create('permissions', function (Blueprint $table) {
$table->id();
$table->string('name');
//To put a description of each of the permissions
$table->string('label')->nullable();
$table->timestamps();
});
//Implement a many to many relationship
Schema::create('permission_user', function (Blueprint $table) {
$table->unsignedBigInteger('permission_id');
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->primary(['permission_id' , 'user_id']);
});
//To group users to apply access levels
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name');
//To put a description of each of the permissions
$table->string('label')->nullable();
$table->timestamps();
});
//Implement a many to many relationship Between grouping and permission tables
Schema::create('permission_role', function (Blueprint $table) {
$table->unsignedBigInteger('permission_id');
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->unsignedBigInteger('role_id');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->primary(['permission_id' , 'role_id']);
});
//Implement a many to many relationship Between roles and users tables
Schema::create('role_user', function (Blueprint $table) {
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->unsignedBigInteger('role_id');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->primary(['user_id' , 'role_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('permissions_user');
Schema::dropIfExists('role_user');
Schema::dropIfExists('permissions_role');
Schema::dropIfExists('roles');
Schema::dropIfExists('permissions');
}
}
کدها مشکلی نداشت چند تا سمیکلون و آکولاد جا اوفتاده بود متد up جایگزین متد قبلی تون کنید
تو AppServiceProvider داخل متد register هم این کدو اضافه کنید
Schema::defaultStringLength(191);
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePermissionsAndRolesTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('permissions', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('label')->nullable();
$table->timestamps();
});
Schema::create('permission_user', function (Blueprint $table) {
$table->unsignedBigInteger('permission_id');
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->primary(['permission_id' , 'user_id']);
});
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('label')->nullable();
$table->timestamps();
});
Schema::create('permission_role', function (Blueprint $table) {
$table->unsignedBigInteger('permission_id');
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->unsignedBigInteger('role_id');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->primary(['permission_id' , 'role_id']);
});
Schema::create('role_user', function (Blueprint $table) {
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->unsignedBigInteger('role_id');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->primary(['user_id' , 'role_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('permission_user');
Schema::dropIfExists('role_user');
Schema::dropIfExists('permission_role');
Schema::dropIfExists('roles');
Schema::dropIfExists('permissions');
}
}
خیلی ازتون ممنونم که زحمت کشیدید و وقت گذاشتید و کدمو بررسی کردید
اما بازم همون ارور رو دارم😭
نمیدونم مشکل از کجاست
خواهش میکنم
متد up هم اشتباه تایپی داره اسم جداول میانه نباید جمع باشه
public function down()
{
Schema::dropIfExists('permission_user');
Schema::dropIfExists('role_user');
Schema::dropIfExists('permission_role');
Schema::dropIfExists('roles');
Schema::dropIfExists('permissions');
}
ببینید مشکل اصلا مربوط به این فایل نیست مایگریشن change_column_from_rooms خطا میده اون فایلو هم اینجا قرارش بدین
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
//use Illuminate\Database\Eloquent\SoftDeletes;
class CreateRoomsTable extends Migration
{
// use SoftDeletes;
/**
@return void
*/
public function up()
{
Schema::create('rooms', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->boolean('enter_me_automatically');
$table->boolean('mute_enter');
$table->boolean('each_user_is_allowed_to_start_the_room');
$table->boolean('login_for_all_users_as_admin');
$table->boolean('requires_administrator_permission_to_login');
$table->timestamps();
// $table->timestamp('deleted_at')->default(0);
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
});
//to using softdelete methode
Schema::table('rooms', function (Blueprint $table) {
$table->softDeletes();
});
}
/**
}
وای متوجه شدم مشکل کجاست
دقیقا مشکل از همون مایگریشن roomsم بود
نمیدونم چطور ازتون تشکر کنم
وااااااقعا بی حد ازتون ممنونم🌺🌺🌺🌺🌺🌺🌺🌺🌺
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟