First Commit
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Subject;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class SubjectPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function view(User $user, Subject $subject): bool
|
||||
{
|
||||
return $subject->is_system || $subject->user_id === $user->id;
|
||||
}
|
||||
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update(User $user, Subject $subject): bool
|
||||
{
|
||||
return $subject->user_id === $user->id || $user->hasRole("superadmin");
|
||||
}
|
||||
|
||||
public function delete(User $user, Subject $subject): bool
|
||||
{
|
||||
return $subject->user_id === $user->id || $user->hasRole("superadmin");
|
||||
}
|
||||
}
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\UserInterest;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Policy for UserInterest model.
|
||||
*/
|
||||
class UserInterestPolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, UserInterest $userInterest): bool
|
||||
{
|
||||
return $user->id === $userInterest->user_id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user