Function Role User Model

For understanding, how the model code works, please refer to country model or company model

Below code create function role user model & migration files.

php artisan make:model FunctionRoleUser -m

Since we need code, and user_id, we add them to Model and Migration file. Code is function code value.

Model class

Replace model class with below code.

Note: Please use the copy button to copy the source code.

class FunctionRoleUser extends Model { use HasFactory; protected $fillable = [ 'code', 'user_id', ]; }
Migration class

With the help of the function role user table, fine control of authorization permission is allowed in the application. For example, create a holiday or delete company record

public function up() { Schema::create('function_role_users', function (Blueprint $table) { $table->id(); $table->string('code'); $table->foreignId('user_id')->constrained(); $table->timestamps(); }); } public function down() { Schema::dropIfExists('function_role_users'); }

To create/update the table to database, we need to run artisan migrate command

php artisan migrate