I’m trying to get the location’s inventory value with the following eloquent query. It properly pulls up everything (location name, address, # of users, etc) except the inventory value which returns …
Tag: eloquent
Laravel sort conversations by last message
I have a Conversation model that has many ConversationMessage models. Now I want to sort the conversations based on the last message of the conversation. Basically like WhatsApp. How do I build the …
Laravel Eloquent version of “NOT IN” SQL
Just need the Eloquent ORM format of this query.. giving a headache for a while. Answer You Can Try this. First you Can Select all Player IDs. $player_ids = TeamRequest::select(‘player_id’)->get(); Then you can find Players Player::whereNotIn(‘user_id’, $player_ids)->get();
How to prioritize result in laravel eloquent
I have a table with 4 columns. I want to display the row based on input and it should be able to display with priority according to the priority fields. example: My table looks like this: I have my test cases below how it should work: Now, I want to prioritize the result from title down to tags based in
Get most recent row with group by and Laravel
Even though there are multiple questions like this I can’t get my query to return the row with the most recent date with a group by. I have the following table.. | message_id | from | to | …
Laravel using where clause on a withCount method
I am trying to do a where clause on withCount method of laravel’s eloquent query builder using this piece of code. and this code is giving me this error. SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘upvotes_count’ in ‘where clause’ (SQL: select , (select count() from upvotes where upvotes.upvoteable_id = posts.id and upvotes.upvoteable_type = AppPost) as upvotes_count from posts where
Laravel 5 Eloquent where and or in Clauses
i try to get results from table with multiple where and/or clauses. My SQL statement is: SELECT * FROM tbl WHERE m__Id = 46 AND t_Id = 2 AND (Cab = 2 OR Cab = 4) How i can get this with Laravel …
How to insert multiple rows from a single query using eloquent/fluent
I have the following query: and as expected I get the following result: Is there a way of copying the above result into another table so that my table looks like this? The problem I have is that the $query can expect any number of rows and so im unsure how to iterate through an unknown number of rows. Answer
MySQL order by field in Eloquent
When I want to define a custom sort order in a MySQL query I can do something like this: ORDER BY FIELD(language,’USD’,’EUR’,’JPN’) What would be the Eloquent ORM version of that? UPDATE: This is …
Laravel – Add custom column in select with Eloquent query buider
this is a simplified use case, only to illustrate what I want to achieve: Considering this query in pure SQL: How can I add the constant active column using query builder ? Here is my Query Builder without the extra column: Answer Simplest would be to use DB::raw