update
This commit is contained in:
parent
1241f19334
commit
64519f8c77
3 changed files with 75 additions and 5 deletions
|
@ -33,11 +33,6 @@ class Customer extends Model
|
|||
});
|
||||
|
||||
static::deleting(function ($model) {
|
||||
$findWebistes = Website::where('customer_id', $model->id)->count();
|
||||
if ($findWebistes > 0) {
|
||||
throw new ('Customer has websites, please delete them first.');
|
||||
return false;
|
||||
}
|
||||
event(new ModelCustomerDeleting($model));
|
||||
});
|
||||
|
||||
|
|
71
web/app/Policies/CustomerPolicy.php
Normal file
71
web/app/Policies/CustomerPolicy.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\Models\User;
|
||||
use App\Models\Website;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class CustomerPolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, Customer $customer): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, Customer $customer): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, Customer $customer): bool
|
||||
{
|
||||
$findWebsites = Website::where('customer_id', $customer->id)->count();
|
||||
if ($findWebsites > 0) {
|
||||
return Response::deny('Customer has websites, please delete them first.');
|
||||
}
|
||||
return Response::allow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, Customer $customer): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, Customer $customer): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -10,8 +10,10 @@ use App\Listeners\ModelCustomerCreatedListener;
|
|||
use App\Listeners\ModelCustomerDeletingListener;
|
||||
use App\Listeners\ModelWebsiteCreatedListener;
|
||||
use App\Listeners\ModelWebsiteDeletingListener;
|
||||
use App\Policies\CustomerPolicy;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
|
@ -30,6 +32,8 @@ class AppServiceProvider extends ServiceProvider
|
|||
public function boot(): void
|
||||
{
|
||||
|
||||
Gate::define('delete-customer', [CustomerPolicy::class, 'delete']);
|
||||
|
||||
Filament::serving(function () {
|
||||
// Using Vite
|
||||
Filament::registerViteTheme('resources/css/app.css');
|
||||
|
|
Loading…
Reference in a new issue