Loading app/Models/Role.php 0 → 100644 +16 −0 Original line number Diff line number Diff line <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Role extends Model { use HasFactory; protected $table = 'CAR_ROLE'; protected $primaryKey = 'ROL_CODE'; } app/Models/RoleAttribution.php 0 → 100644 +12 −0 Original line number Diff line number Diff line <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class RoleAttribution extends Model { protected $table = 'CAR_ROLE_ATTRIBUTION'; public $timestamps = false; } app/Models/User.php +11 −1 Original line number Diff line number Diff line Loading @@ -35,11 +35,21 @@ public function checkPassword($password) } } /** * Get the roles attributed to the user. */ public function roles() { return $this->belongsToMany(Role::class, 'CAR_ROLE_ATTRIBUTION', 'US_ID', 'ROL_CODE'); return $this->belongsToMany(Role::class, RoleAttribution::class, 'US_ID', 'ROL_CODE'); } /** * Check if the user has a given role. * * @param string $roleCode the code of the role to check * @return bool true if the user has the role, false otherwise */ public function hasRole($roleCode) { return $this->roles->contains('ROL_CODE', $roleCode); Loading resources/views/test.blade.php +1 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ <body> @if ($user->checkPassword('securepassword')) <p>Match</p> <p> {{$user->hasRoles('SEC')}} </p> @else <p>Unmatch</p> @endif Loading routes/web.php +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ return view('welcome'); }); Route::get('/', function() Route::get('/test', function() { return view('test', ['user' => User::find(1)]); }); Loading Loading
app/Models/Role.php 0 → 100644 +16 −0 Original line number Diff line number Diff line <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Role extends Model { use HasFactory; protected $table = 'CAR_ROLE'; protected $primaryKey = 'ROL_CODE'; }
app/Models/RoleAttribution.php 0 → 100644 +12 −0 Original line number Diff line number Diff line <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class RoleAttribution extends Model { protected $table = 'CAR_ROLE_ATTRIBUTION'; public $timestamps = false; }
app/Models/User.php +11 −1 Original line number Diff line number Diff line Loading @@ -35,11 +35,21 @@ public function checkPassword($password) } } /** * Get the roles attributed to the user. */ public function roles() { return $this->belongsToMany(Role::class, 'CAR_ROLE_ATTRIBUTION', 'US_ID', 'ROL_CODE'); return $this->belongsToMany(Role::class, RoleAttribution::class, 'US_ID', 'ROL_CODE'); } /** * Check if the user has a given role. * * @param string $roleCode the code of the role to check * @return bool true if the user has the role, false otherwise */ public function hasRole($roleCode) { return $this->roles->contains('ROL_CODE', $roleCode); Loading
resources/views/test.blade.php +1 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ <body> @if ($user->checkPassword('securepassword')) <p>Match</p> <p> {{$user->hasRoles('SEC')}} </p> @else <p>Unmatch</p> @endif Loading
routes/web.php +1 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ return view('welcome'); }); Route::get('/', function() Route::get('/test', function() { return view('test', ['user' => User::find(1)]); }); Loading