🔁Update Request
this method returns RedirectResponse or JsonResponse based on the request type. and we get the request type by check if the route has splade middleware or not.
this method accept some arguments:
requestthe request objectmodelthe model you want to getvalidationthe validation rules you want to usemessagethe message you want to return with the responsevalidationErrorthe message you want to return if the validation failedredirectthe redirect route you want to redirect tohasMediaif you want to get the media of the model or notcollection [array]the media collection you want to get as array take true if it's multi or false if it's singleapiif you want to return JsonResponse or not
public function update(Request $request, \App\Models\User $model): RedirectResponse|JsonResponse
{
$response = Tomato::update(
request: $request, //Required
model: $model, //Required
validation: [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
],
message: __('User updated successfully'),
redirect: 'admin.users.index',
hasMedia: true,
collection: [
'avatar' => false,
'gallery' => true
],
api: true,
);
if($response instanceof JsonResponse){
return $response;
}
return $response->redirect;
}Last updated
Was this helpful?