Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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.

Last updated 9 years ago.
0

Try this: App\Offer::with('tags')->->whereNotIn('id', array(1, 2, 3))->get();

0

@JuanDMeGon

Thanks for the response, but I don't think that is going to help me. I want to minimize the query size.

@Zolax

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:

  • Set #1: Get offer_ids tagged with Sweet
  • Set #2: From all the offers, pick the ones which are not in the Set #2

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.

0

So you don't want to select tags with specific name right?

0

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.

Last updated 9 years ago.
0

Zolax said:

So you don't want to select tags with specific name right?

Yeah, that's what i'm trying to do.

0

@nenadstojanovikj Try this one:

App\Offer::with('tags')->where(function($query){
     $query->where("name", "!=", "ExampleOne")
           ->orWhere("name", "!=", ËxampleTwo");
})->get();

Last updated 9 years ago.
0
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.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.