You are viewing documentation for an outdated version. It is no longer supported!
Delete Resource
For requests that are intended to delete or soft-delete a resource, you can use the DeleteSingleResourceRequest
abstraction.
Example Request
use Aedart\Http\Api\Requests\Resources\DeleteSingleResourceRequest;
use Illuminate\Database\Eloquent\Model;
use App\Models\User;
class DeleteUser extends DeleteSingleResourceRequest
{
public function findRecordOrFail(): Model
{
return User::findOrFail($this->route('id'));
}
public function mustEvaluatePreconditions(): bool
{
return true;
}
}
Example Action
Route::delete('/users/{id}', function (DeleteUser $request) {
$user = $request->record;
// E.g. soft-delete
$user->delete();
return UserResource::make($user);
})->name('users.destroy');
Authorisation
Authorisation checks is performed by the authorizeFoundRecord()
method (see source code for details). The request will check against a destroy
ability. From the above shown examples, a users.destroy
ability is checked.
Request Preconditions
See Show Request for additional information.