Yes, there is a little "gotcha" with Eloquent and a query builder. Try the code below;)
$query = Page::where('slug', '=', $slug); if ($hidden == 1) { $query = $query->where('hide', '=', 1); } $article = $query->first();
Note the purpose of the $ request in the conditional expression. This is because the first is where (statically called) returns another object to the request object in a conditional expression. One way around this, I believe, due to a recent commit, looks like this:
$query = Page::where('slug', '=', $slug)->query();
This will return the request object, and you can do what you want according to normal (instead of re-assigning the request $).
Hope this helps.
source share