opnform/app/Policies/TemplatePolicy.php

48 lines
1.1 KiB
PHP

<?php
namespace App\Policies;
use App\Models\Template;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class TemplatePolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can create models.
*
* @param \App\Models\User $user
* @return \Illuminate\Auth\Access\Response|bool
*/
public function create(User $user)
{
return $user !== null;
}
/**
* Determine whether the user can update the model.
*
* @param \App\Models\User $user
* @param \App\Models\Template $template
* @return mixed
*/
public function update(User $user, Template $template)
{
return $user->admin || $user->template_editor || $template->creator_id === $user->id;
}
/**
* Determine whether the user can delete the model.
*
* @param \App\Models\User $user
* @param \App\Models\Template $template
* @return mixed
*/
public function delete(User $user, Template $template)
{
return $user->admin || $user->template_editor || $template->creator_id === $user->id;
}
}