Wrap it in a response
return response(view('pages.render-layout', compact('page')), 404);
Hi all. I've been building a page builder (which is working nicely) but what I'd like to do is enable the admin to create/edit the error 404 page (rather than use the built-in 404 page).
They can create their own content in the admin area and in the frontend it displays pages simply using a '/page/UNIQUE_ID/category/some-sort-of-slug' route.
I've defined a page (using the unique ID) as an error 404 page and have coded the controller so that if a page with a unique ID cannot be found (so its been deleted), to redirect to the 404 page (lets say the ID is 25).
That works fine, but of course its just an ordinary page. We need it to be recognised as a 404 page with a proper 404 response code.
I've tried returning the view of the error 404 page as follows…
return view('pages.render-layout', compact('page'), 404);
…and also as…
return redirect('/page/' . $page->error_404_page_id, 404);
…but neither works when the 404 is there (remove the 404 the page loads on both fine).
I'm obviously getting something wrong, can anyone help me out?
Thanks for any suggestions!
Wrap it in a response
return response(view('pages.render-layout', compact('page')), 404);
Please or to participate in this conversation.