eskimo
eskimo

Reputation: 2624

Laravel return view from method in controller

In a Laravel 5.7 controller, this works:

class SearchController extends Controller
{
    return view('test);
}

But this doesn't (the result is a blank page, no html is generated, no error message is shown)

class SearchController extends Controller
{
    $this->show_view();
}

private function show_view()
{
    return view('test);
}

If I add dd('this is a test'); in the private function show_view right before return view('test);, that message is displayed so the show_view method is called properly, but returning the view doesn't work. Why?

Upvotes: 0

Views: 252

Answers (1)

ceejayoz
ceejayoz

Reputation: 180004

Change $this->show_view(); to return $this->show_view(); and it should work. You're getting a blank page because while you successfully render the view, you don't return it back to Laravel at all.

Upvotes: 1

Related Questions