mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-10-14 23:02:05 +02:00
* feat(admin): migrate db dumps from github to platform * style: fix StyleCI findings
40 lines
849 B
PHP
40 lines
849 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Middleware\Models;
|
|
|
|
use App\Models\BaseModel;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use RuntimeException;
|
|
|
|
/**
|
|
* Class WithoutTrashed.
|
|
*/
|
|
class WithoutTrashed
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param Request $request
|
|
* @param Closure(Request): mixed $next
|
|
* @param string $modelKey
|
|
* @return mixed
|
|
*/
|
|
public function handle(Request $request, Closure $next, string $modelKey): mixed
|
|
{
|
|
$model = $request->route($modelKey);
|
|
|
|
if (! $model instanceof BaseModel) {
|
|
throw new RuntimeException('without_trashed should only be configured for models that can be soft deleted');
|
|
}
|
|
|
|
if ($model->trashed()) {
|
|
abort(403, 'Deleted Model');
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|