Detect when a filter returns nothing?


I’m trying to do a “secret” page in my portfolio, like tags but not directly accessible (ie for a job interview, I can send a filtered URL depending the company making the interview, or what I want to show to them).

I figured out for the tag system thanks to the documentation, but I was wondering if there was a way to show a message or make a redirection if the tag entered does not exist.

Example :

  1. example.tld/view/filter:companyhiringname = show projects that I want to show them directly (I guess it’s OK even if I can’t display a project I want)

  2. If no filter is set in URL, just display featured projects (this part is OK)

  3. example.tld/view/filter:randomgibberishwhateverfrkhqklsfjgk = redirect on portfolio page, or just a message

I’ve tried to test if $project (wich is my filter result in controller) is empty with if (empty($projects) but it doesn’t seem to work.

What I want is : if the tag returns nothing (aka does not exist) then do something (message or redirect or whatever)

You can count the number of projects in the collection like this:

if($projects->count() === 0) {
// display a message or redirect

ouh yeah \o/. I was searching too far.

thanks !