osb/app/Models/Policies/InvoicePolicy.php
2021-06-29 16:40:54 +10:00

90 lines
1.7 KiB
PHP

<?php
namespace App\Models\Policies;
use Illuminate\Auth\Access\HandlesAuthorization;
use App\Models\{Invoice,User};
class InvoicePolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view the service.
*
* @param User $user
* @param Invoice $o
* @return mixed
*/
public function view(User $user, Invoice $o)
{
// If this is a service for an account managed by a user.
return ($user->invoices->pluck('id')->search($o->id) !== FALSE)
// The user is the wholesaler
OR $user->isWholesaler()
// The user is the reseller
OR $user->all_accounts()->pluck('id')->search($o->account_id);
}
/**
* Determine whether the user can create services.
*
* @param User $user
* @return mixed
*/
public function create(User $user)
{
return TRUE;
}
/**
* Determine whether the user can update the service.
*
* @param User $user
* @param Invoice $o
* @return mixed
*/
public function update(User $user, Invoice $o)
{
return $user->isWholesaler();
}
/**
* Determine whether the user can delete the service.
*
* @param User $user
* @param Invoice $o
* @return mixed
*/
public function delete(User $user, Invoice $o)
{
return $user->isWholesaler();
}
/**
* Determine whether the user can restore the service.
*
* @param User $user
* @param Invoice $o
* @return mixed
*/
public function restore(User $user, Invoice $o)
{
return $user->isWholesaler();
}
/**
* Determine whether the user can permanently delete the service.
*
* @param User $user
* @param Invoice $o
* @return mixed
*/
public function forceDelete(User $user, Invoice $o)
{
return $user->isWholesaler();
}
}