updated permissions

This commit is contained in:
Edward Tirado Jr 2025-12-30 21:15:42 -06:00
parent 8f47f40b03
commit 83f7073b18
31 changed files with 1467 additions and 901 deletions

View file

@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
@ -18,4 +19,9 @@ class MovieList extends Model
{
return $this->belongsToMany(Movie::class);
}
public function owner(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
}

10
app/Models/Permission.php Normal file
View file

@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Permission extends Model
{
//
}

10
app/Models/Role.php Normal file
View file

@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
//
}

View file

@ -5,9 +5,12 @@ namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Context;
use Illuminate\Support\Str;
use Laravel\Fortify\TwoFactorAuthenticatable;
@ -44,6 +47,19 @@ class User extends Authenticatable
return $this->hasOne(UserProfile::class);
}
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class);
}
public function hasRole(string $role): bool
{
if (Context::hasHidden('roles')) {
return in_array(strtolower($role), Context::getHidden('roles'));
}
return $this->roles->contains('name', strtolower($role));
}
/**
* Get the user's initials
*/