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

SimonAngatia's avatar

How to redirect/return view from API route controller

Hi, I am working on some payment API and using some controller to handle the request sent through that Api. Now I want to redirect to another page immediately that request has been successful but then it is not working on that route.

//My controller:
$curl_response = curl_exec($curl);
        if($curl_response){
            $this->confirmForm();
        }```

//confirmForm Method:

 public function confirmForm(){
        $page_title = "Lipa na M-PESA confirmation";
        return view(activeTemplate() . 'payment.mpesa-confirm', compact('page_title'));
    }

The curl_response is running successfully but it is not redirecting. How do I solve this?
0 likes
3 replies
programators's avatar

in your controller please:

  return redirect('/your-route')
            ->with('message', 'Payment successfull');

in blade

     @if(session('message'))
              {{ session('message')}}

       @endif
SimonAngatia's avatar

I said API route controller. The normal redirecting don't work

Please or to participate in this conversation.