crslp's avatar
Level 9

can't call view from static function in controller

Hey guys. I am working on a seacht-filter for my app.

In my web.php I got this closure:

// http://localhost:8000/filter?c=music&date=18_03_2017&timeFrom=23_00
Route::get('/filter', function (Request $request) {

  App\Http\Controllers\EventController::indexByFilter($request);
});

For this, the function indexByFilter must be static:

public static function indexByFilter(Request $request)
    {
      // some code

      return view('event.index')->with('tdt', $tdt);
    }

The last line,

return view('event.index')->with('tdt', $tdt);

does not work. I don't even get an error-message. Just a blank page.

I think, the static-thing causes this issue. But I can't solve this by myself. Thank you for any suggestion!

0 likes
2 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

Return whatever to the calling function and then render your view.

2 likes
crslp's avatar
Level 9

Thank you! First, I did not understood what you're saying. Now I got it:

Route::get('/filter', function (Request $request) {
return App\Http\Controllers\EventController::indexByFilter($request);
});

Thank you!

Please or to participate in this conversation.