NNNN
NNNN

Reputation: 19

Want to redirect to a page

I want to redirect to the product page. This is my controller function.

public function RegisterBusiness(Request $request){

    DB::beginTransaction();
    try {

        if(session()->has('user_id')){
            $request['mybiz_users_id']=Session()->get('user_id');
        }

        $this->businessTempService->insertRegisteredBusinessDetails($request);

        DB::commit();
        
        return $this->sendResponse('success', 'Registered Successfully, Thank You!', '', 200,route('web.registration.advanced-product-registration'));
        
    } catch (Exception $ex) {
        DB::rollback();
        Log::error($ex);

        return $this->sendResponse('error', 'Something went wrong', '', 422);
    }
}

But it is not working.

It loads this page

Upvotes: 0

Views: 72

Answers (2)

STA
STA

Reputation: 34668

This is not an error, its a json response , if you redirect to product page then change

return $this->sendResponse('error', 'Something went wrong', '', 422);

to

return view('product.index'); 

or, with name route :

return route('product');

Upvotes: 2

SEYED BABAK ASHRAFI
SEYED BABAK ASHRAFI

Reputation: 4271

You should use \request()->expectsJson() to find out whether you need a json response or not.

if (\request()->expectsJson()){
    return $this->sendResponse('success', 'Registered Successfully, Thank You!', '', 200,route('web.registration.advanced-product-registration'));
}else{
    return back();
}

Upvotes: 0

Related Questions