I have a problem understanding what is the use of <>
in ->where('id', '<>', $id)
protected function getRelatedSlugs($slug, $id = 0){
return Product::select('slug')
->where('slug', 'like', $slug.'%')
->where('id', '<>', $id)->get();
}
I have a problem understanding what is the use of <>
in ->where('id', '<>', $id)
protected function getRelatedSlugs($slug, $id = 0){
return Product::select('slug')
->where('slug', 'like', $slug.'%')
->where('id', '<>', $id)->get();
}
See the documentation:
The second argument is an operator, which can be any of the database's supported operators
So look that up in the manual for your database.
You didn't say what database you were using, so let's look at PostgreSQL 13:
datatype <> datatype → boolean: Not equal
So it means "Where the id is not equal to the value of $id
.
In other words, when you get the slugs related to the current one, you don't want to return the current one in the list.