Skip to content

Commit

Permalink
User Roles Permission Table in DB with models file and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
meowfu0 committed Oct 4, 2024
1 parent fc65649 commit a43e411
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
85 changes: 85 additions & 0 deletions app/Http/Controllers/UserRolesPermissionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App\Http\Controllers;

use App\Models\UserRolesPermission;
use Illuminate\Http\Request;

class UserRolesPermissionController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
* @param \App\Models\UserRolesPermission $userRolesPermission
* @return \Illuminate\Http\Response
*/
public function show(UserRolesPermission $userRolesPermission)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Models\UserRolesPermission $userRolesPermission
* @return \Illuminate\Http\Response
*/
public function edit(UserRolesPermission $userRolesPermission)
{
//
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\UserRolesPermission $userRolesPermission
* @return \Illuminate\Http\Response
*/
public function update(Request $request, UserRolesPermission $userRolesPermission)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param \App\Models\UserRolesPermission $userRolesPermission
* @return \Illuminate\Http\Response
*/
public function destroy(UserRolesPermission $userRolesPermission)
{
//
}
}
11 changes: 11 additions & 0 deletions app/Models/UserRolesPermission.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class UserRolesPermission extends Model
{
use HasFactory;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUserRolesPermissionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_roles_permissions', function (Blueprint $table) {
$table->id();

// Foreign keys
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('role_id');
$table->unsignedBigInteger('permission_id');

// Foreign key constraints with cascade on delete
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');

// Timestamps
$table->timestamp('created_at')->useCurrent();
$table->timestamp('modified_at')->nullable()->useCurrentOnUpdate();
$table->timestamp('deleted_at')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('user_roles_permissions', function (Blueprint $table) {
// Dropping foreign key constraints
$table->dropForeign(['user_id']);
$table->dropForeign(['role_id']);
$table->dropForeign(['permission_id']);
});

Schema::dropIfExists('user_roles_permissions');
}
}

0 comments on commit a43e411

Please sign in to comment.