osb/app/Models/Policies/InvoicePolicy.php

90 lines
1.7 KiB
PHP
Raw Normal View History

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