Monday 9 September 2019

addClause always returns empty collection

I have an Article model and am using $this->crud->addClause('where','user_id',backpack_user()->id); to limit the articles shown to those belonging to the currently logged in user.

I now want to further filter my articles by only showing articles that have a certain page_id - in fact, I can do this without any hassle:

$this->crud->addClause('where','page_id', "=", "154");

Now only articles that have a page_id of 154 are shown.

Obviously I want a dynamic variable for page_id, so my url looks like this

http://example.com/admin/articles/154

and I extract the last parameter like this:

$segments = request()->segments();
$page_id = $segments[count($segments)-1]; //get last segment, contains "154"

Now my problem is that for some obscure reason, whenever I try to use

$this->crud->addClause('where','page_id', "=", $page_id);

The collection is empty, even tho dd()'ing $page_id shows it is set and contains "154". I have even tried to cast $page_id to int like this and in fact it becomes an int but still the same problem (empty collection):

$page_id = (int)$segments[count($segments)-1]; //shows 154

Thanks for any help!



from addClause always returns empty collection

No comments:

Post a Comment