Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

indersein's avatar

Laravel flugger/laravel-responder for Api response

hey everyone

My problem is I am using flugger/laravel-responder for API response this is working fine send response good but I am using laravel request for validation so my request class validations fail then page redirect to home page

My user register code

    public function userRegister(UserRegisterRequest $request)
    {

        //user register code here
        return responder()->success([
            'form' => ['done'],
            'dispatch' => ['domne']
        ])->respond();
    }



This is my request code


  public function rules()
    {
        $rules = [
            'email' => 'required|email|unique:users,email',
            'password' => 'required',
        ];
        return $rules;
    }


0 likes
7 replies
bugsysha's avatar

I know this is probably not something you want to hear, but in my experience all packages like the one you are using become inflexible at some point while making changes to the app.

I strongly recommend to remove it and just build your own system or just use core framework features.

devingray_'s avatar

Create a new Middleware Called

ForceApplicationJSON and add to all requests that need this.

The middleware should contain

public function handle($request, Closure $next)
{
    $request->headers->set('Accept', 'application/json');
    return $next($request);
}

This will stop Laravel from making a redirect and return json errors instead.

Alternatively ensure all requests made have the

'Accept' 'application/json' in the headers

1 like
devingray_'s avatar

If it was solved here please accept it as best answer to help others who may search for this and if solved somewhere else please add the solution and mark as best answer

Please or to participate in this conversation.