You can use the $visible or $hidden attributes in the Offer and Tag models.
Just add into the $visible array attribute the values (data) that you wnat to be visible or to the $hidden array the values to hide.
For example:
class Offer extends Model { $hidden = ['created_at', 'updated_at', 'id', 'hidenAtribute']; .... ....
Hope it helps :)
You can see this Laravel course to learn more details about Laravel: https://www.udemy.com/laravel-5-course-learn-php-laravel/?couponCode=forum
Best wishes.
Try this:
App\Offer::with('tags')->->whereNotIn('id', array(1, 2, 3))->get();
Thanks for the response, but I don't think that is going to help me. I want to minimize the query size.
I tried that, but there is a logical problem. For example if an Offer
is tagged with tags ['Veggie', 'Sweet'] and let's say the user doesn't like Sweet, it will still pull that offer since he doesn't like Sweet, but likes Veggie. I'll paraphrase the working SQL query:
Example:
User doesn't like 'Sweet'
Offers [1,5,7] are tagged with 'Sweet' and with Fruit
From all Offers [1..10] get all offers which are not [1,5,7]
I think this makes sense.
App\Offer::with([ 'tags' => function ($query) { $query->whereIn(['tag_name' => ['exampleOne', 'Exampletwo']]) } ])->get();
you can change query base on tag name or id. hope this will help you.
Zolax said:
So you don't want to select tags with specific name right?
Yeah, that's what i'm trying to do.
@nenadstojanovikj Try this one:
App\Offer::with('tags')->where(function($query){
$query->where("name", "!=", "ExampleOne")
->orWhere("name", "!=", ËxampleTwo");
})->get();
return Offer::whereDoesntHave('tags', function ($q) use ($tags) {
$q->whereIn('id', $tags);
})->get();
This is what I finally ended up with. I think it looks pretty clean.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community