If I use models this is easily resolved, but if I don’t have the availability of using models, would it be possible to get the result equivalent to ->with() with DB::table? Answer No, Here is why Laravel models are using Eloquent, which is an ORM library. For example, a class model could have many teachers relations, and if you want
Tag: eloquent
How to group some data on basis of two fields in Laravel?
Here I’m trying to keep track of my Employees Skills like when they are added, when removed and then new skills are added. So, I’m getting storing them in the database as follows: Then Retrieving the data as follows: And then showing them in the blade as: So as expected in the browser it shown like this: But I want
How to add extra parameter in with condition in laravel
I want to add extra parameter type in with condition. I have no type column in matches table. Expeacted Out put is: Answer If the value of “type” is static you can try something like this: Add this line (import) at the begging of the file: Then:
laravel relationship not loading
I’ve got a Product and a Category models: In my controller, I’m retrieveing all products and wanted to return the category object the product belongs to in the response, so I’m doing: and my resource looks like: but the response I’m getting is: I tried loading the relationship differently: but the result is the same. It seems that the relationship
how to compare two separate relations fields with each other in whereHas laravel?
I use laravel 9 and I have 3 model here : order shop accepted_order notice : accepted_order is not pivot table Now I want to get accepted_orders where : or and both query orderBy created_at desc. how can I use whereHas query that compare two separate relations field with each other? thanks Answer I found it
laravel eloquent model record not fetched
I am facing a strange issue. When I do NumberConfiguration::all() I receive the following result: but in the database I have actually 2 record: I didnt find anything what can cause this problem, that not all record are represented by the eloquent model biding. I am using postgresql database. There is an observer in the parent class, but even if
How to join two tables in mysql that has different connections of mysql on different server laravel
I tried this query below and got a database query builder not converted to string error Answer Eloquent does not support joining data from different connections. If both databases are stored on different servers, the only thing you can do is to fetch relevant data from both connections and then join it programatically. Joining data from different databases is possible
Eloquent relationship returns nothing
I am trying to make a system that allow users to create playlists which add on it movies there favorites movies or songs. I named the main model “Top”. I also have models : User, Category, Liste_top (this name is bad but it make de junctions beetween a Top and a Movie/Song. A better name, I guess, would be something
How to change Eloquent Builder’s connection?
I have a Eloquent Builder and two database connections(mysql_server1, mysql_server2) as below: Now how can I change the connection of $builder? Any helps would be appreciated Answer Need to get the Query from Eloquent Builder and set a new connection to that and set the new query to the Eloquent Builder as below:
how to simplify this complex query
This is an extract of one of my php functions. I’m struggling to get this optimized as is super slow, as I need to load all interview records, and then check if the current user is either assigned as user_id on the interview record, or if the user->id is in the interviews shared_user_ids which is json I’m also using PostgreSQL