🔁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:

  • request the request object

  • model the model you want to get

  • validation the validation rules you want to use

  • message the message you want to return with the response

  • validationError the message you want to return if the validation failed

  • redirect the redirect route you want to redirect to

  • hasMedia if you want to get the media of the model or not

  • collection [array] the media collection you want to get as array take true if it's multi or false if it's single

  • api if 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