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

vincej's avatar
Level 15

Why does my controller divert to a different view?

I have two views, one called 'manualRegistration', the other called 'newManualRegistration.

I enter a date into the first one. JS grabs it passes onto Axios. Axios calls the controller below:

 public function getRegistration(Request $request){

        $registeredChildren  = DB::table('attendance')
            ->join('child', 'child.child_id', '=', 'attendance.child_id')
            ->select('child.child_id','child.childFirstName', 'child.childLastName','timeIn','timeOut','date')
            ->whereDate('date', $request->date)
            ->orderBy('child.childFirstName')
            ->get();

           return view('newManualRegistration',compact('registeredChildren'));
    }

For some reason Laravel ignores the required view, 'newManualRegistration', and sends the app back to the original view, 'manualRegistration' view.

I have tried using a redirect like this: return redirect('newManualRegistration', compact('registeredChildren')); but that did not help.

So - how can I get my app to go to the correct view?

0 likes
7 replies
Snapey's avatar

it cant be calling this controller?

durairaj's avatar

did you redirect correctly on controller function, Check your route ?

vincej's avatar
Level 15

perhaps I am being very stupid. I am returning a view without passing through a route. Can this be done? Or MUST i use an intermediate route?

Sathish NP's avatar

Clear the cache and create new function and controller with different names. I hope this will work

vincej's avatar
Level 15

In the end I got fed up trying to get this to work - there was some kind of issue with JS, so bugger it, I did it the old fashioned way with form action

Thanks for all your contributions.

1 like

Please or to participate in this conversation.