#### Category : orm

Is there a way to use additional conditions when defining an eloquent relationship in a model? Let’s say I have: public function researchtopic() { return $this->belongsTo(‘AppResearchTopic’, ‘taggable_id’); } But i want to add an additional where condition to use a 2nd column in the relationship as well. How would I add a 2nd condition for: .. Read more My User.php Model function is this public function send_connection_requests() { return$this->hasMany(‘AppModelsConnectionRequest’,’from_user’); } public function received_connection_requests() { return $this->hasMany(‘AppModelsConnectionRequest’,’to_user’); } and my coonectionRequest realtionship is this-> public function send_connection_requests() { return$this->belongsto(‘AppUser’,’id’); } public function received_connection_requests() { return $this->belongsto(‘AppUser’,’id’); } ` When I am calling function @foreach (Auth::user()->send_connection_requests as$request) {{request->to_user}} @endforech I’m only getting ..

please what is the correct way of getting data from the MN table where one product has assigned multiple combinations of Mark / Model / Year. E.g. product with ID 1 has following in mmis table: id | product_id | mark_id | model_id | year_id 178 1 1 1 2 177 1 2 1 3 ..

i have a view which displays some places and i’m fetching this data from my API, the model places have many to many relationship with categories. Is there any way i can fetch both model data from the controller? Like i have this function to fetch all the places, how can i fetch their categories ..

Let’s say that i want to exclude certain instances of a vendor model from my queries, how can i add a global scope to that model instead of adding a where() condition to every query? Sourc..

Having a hard time understanding how to order my Laravel model by a nested relationship. Here are the Models. User.php // Has many small_groups through a pivot table public function small_groups() { return $this->belongsToMany(‘AppModelsSmallGroup’)->withPivot(‘type’)->withTimestamps(); } SmallGroup.php // Has many SmallGroupLessons public function small_group_lessons() { return$this->hasMany(‘AppModelsSmallGroupLesson’); } SmallGroupLessons.php // Has many SmallGroupLessonComments public function small_group_lesson_comments() ..

I have these two models with one to one relationship. "products" id name minimum_required "product_data" id product_id price oh_hand I want to get the count of product_data where its on_hand is less than its related product’s minimum_required. I’ve tried subqueries and I still can’t figure it out. The query I want may looks something like ..

I have a query like this, to make count from my query, I want finding where id is with the minimum count, with result id in an array $id = Departemen::where(‘open’, 1)->where(‘name’, ‘LIKE’, ‘%LOKET%’)->pluck(‘id’)- >toArray();$matchThese = [‘called’ => 0, ‘onserved’ => 0]; $smaller = Queues::select(‘department_id’,DB::raw(‘count(*) as total’)) ->where($matchThese)->whereIn(‘department_id’, $id)->groupBy(‘department_id’)->get(); Sourc.. Read more i want to sort the values of the table in descending order and the null value is in the first like this: null null 2020-09-27 16:36:17 2020-09-27 18:20:30 2020-09-27 22:45:26 2020-09-28 02:11:14 2020-09-28 10:31:43 I used the following code but it did not work Source::orderBy(‘last_rank_update’, ‘asc’)->get(); how can i achieve that? Sourc.. Read more Firstly, feel free to edit my post if I have chosen a wrong term for my title. I chose the term transitive because it felt similar to the idea of transitivity in mathematics to me. Anyway, I have three tables departments, users and tags. Each user can belong to one department and each department has .. Read more I’m new to this questions thing so please bear me I’m using illuminate/database php library, more specific the IlluminateDatabaseEloquentModel, so I created a class that extends from this and try to query one single record. When I print the results I know is fetching the information as you can see by the protected attributes, but .. Read more i have developed a management system using laravel. but when data rows increased it’s take 5-7 seconds to load. in my database have 5000 rows. i have tried Cashing. but i can’t use that because database values getting change time to time. any suggestions? Thanks in Advance Sourc.. Read more I’m working on a Laravel project. I usually get database relations through Eloquent ORM, like belongsToMany or hasOne and such. But when you get data from these kind of relations, does it run an extra query? Is there a performance difference between:$this->hasOne(Model::class) and Model::find($this->some_id) ? Thank you very much. Sourc.. Read more i have three tables, products , discount ,and dicount_products. the discount table have the discount data, and the discount_products have the id’s of the product and the discount tables, to make a connection bettwen them. in my model products , am trying to accsess the discount throught the relationship table by doing this //the discount .. Read more hello sorry for long question I want to create some attribute with values in my panel admin for my products. and I like to save the attribute with its values after entering for first time. for exmale I have a product and I make a color attribute with value of red for that. next time .. Read more I have the following table structure in MySQL database: Products id – integer name – string user_id -string Users user_id – string password – string person_id – integer Persons person_id – integer name – string email – integer I am using hasOneThrough relationship on Products model to get the details about the Person, who is .. Read more I am trying to insert data in orders table and then save order details in order_details table. Following is the code that I’m trying$order = Order::create($request->all());$order->order_detail()->insert($request->order_detail); //$request->order_detail is an array In my model I have provided relationships Order Model public function order_detail(){ return $this->hasMany(OrderDetail::class, ‘order_id’); } Order Detail Model public function order(){ return .. Read more I am trying to save multiple records in DB and have an array which looks like:-$insert_data = array( array(record 1), array(record 2), array(record 3) ) Now, I tried two options:- Model::create($insert_data) But it doesn’t create any entry in DB. Model::insert($insert_data) It’s creating entry in DB with null datestamps. I wanna insert multiple records with ..
I have the following code: $ids =$adGroupsOfUser->pluck(‘id’); $permittedTables = extensiontables_registry::whereHas(‘ad_groups’, function($q){ $q->whereIn(“ad_group_id”,$ids); })->pluck(‘extensiontable_name’)->toArray(); I get this error: local.ERROR: ErrorException: Undefined variable: ids in E:aether-backendappHttpHelpersmodelInteractions.php:51 Why is $ids not visble in the callback of whereHas()? What can I do to “get it inside”? Source: Laravel Sta.. Read more I have a many-to-many relationship between extensiontables_registry and Ad_groups The pivot table is extensiontables_registryxad_groups Now I have this code:$permittedTables = extensiontables_registry::has(“ad_groups”)->get(); I want to see what this gets me so I do: log::info($permittedTables); And I get this error: [2020-05-11 07:32:23] local.ERROR: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘extensiontables_registryxad_groups.extensiontables__registry_id’ in ‘where clause’ in .. Read more How to represent the query sentence in Laravel (Query builder and Eloquent) select c.image_path, c.image_x, c.image_y from banners b left outer join banner_images i on b.banner_id=i.banner_id left outer join images_links l on i.banner_image_id=l.object_id left outer join images c on l.image_id =c.image_id WHERE b.status LIKE ‘A’ AND b.type LIKE ‘G’ AND l.object_type LIKE ‘promo’; Source: Laravel .. Read more Am trying to make a laravel search which has 4 columns. What am trying to do is, if the user search using one input field they will get the related result and if the user use multiple search input fields they will get the related result. Here’s my form: <form action=”{{ route(‘properties-list’) }}” method=”POST” role=”search”> .. Read more I want to insert date only when updateOrCreate works as CREATE & update date only when updateOrCreate works as UPDATE. UpdateOrCreate Method work absolute fine. but when i am trying to check +wasRecentlyCreated so that i can update or insert date accordingly. this property is always showing +wasRecentlyCreated: false. However, data updating & creating as .. Read more I have two Models (Store, Product) and Relationship hasMany public function products(){ return$this->hasMany(Product::class); } And I want to return response collection, in class StoresCollection extends ResourceCollection public function toArray($request) { return$this->collection->map(function ($item) { return [ ‘id’ =>$item->id, ‘seller_id’ => $item->seller_id, ‘store_product’ =>$item->products()->get(), ]; }); } But I don’t want to return ..