I have a table call labels_table. id label 1 A_1_1 2 A_1_2 3 A_2_1 4 A_4_1 5 A_10_1 6 A_11_1 I need to select all the labels for A_1 group. A_1_1 and A_1_2 should be the correct labels. I used the following query. sql Larval But both SQL and laravel queries returns all A_1_1, A_1_2, A_10_1 and A_11_1. But I
Tag: eloquent
How to use the passed data in to a sql query?
How do I pass the $id into my $record SQL query and what is the eloquent query as well? I want to do this because the user_id is the foreign key from borrows. I want to pull data from payment_records that have the same id with the selected id. This is the show method where I passed the id and
Laravel Eloquent Equivalent for MYSQL DISTINCT query multiple columns
Is there an equivalent query for this in eloquent? Answer Try something like this:
Laravel (8.x) Is there a better Eloquent query for this many-to-many filtering problem?
What I have movies many-to-many stars movies many-to-many tags studio one-to-many movies I pass studio name, star name and/or tag name as optional query strings What I need Select all movies with tag and star and studio if all 3 are passed as params Select all movies with tag and star if those 2 are passed as params Select all
Laravel Eloquent, group by week and display start and end of week
I have the following code, which return a collection of Orders grouped by week. The result is the following, with, Obviously “05” being the week number. But to the proyect i’m currently working this is not the way I want to show it. Is there any way to display or return the week start and week end and not the
Laravel query Builder Select from subquery
I’m trying to convert a sql query to a Laravel Query builder, but i find hard understand which is the best way for FORM SUBQUERY in Laravel, because if i’m not wrong, is not something that you can normally do whit query builder, but you should implement in raw. is this right? and how should translate this? I could translate
How to get sum of weight as total_weight from one table and store it in another table
I had two similar fields namely total_weight that is in my phyto table and weight that is in my phyto_species table shown below CreatePhytosTable CreatePhytoSpeciesTable I have been trying to sum weight using array_sum() as total weight and then assign it to ‘total_weight’ => $totalweight] shown below however when I save the error says Undefined variable: totalweight. I would like
exists query does not return relevant result
I have a Laravel application with this Eloquent query: $products = Product::where(‘name’, ‘LIKE’, “%{$value}%”) ->whereHas(‘categories’, function($q) { $q->where( ‘slug’, ‘…
Eloquent hasMany doesn’t load collection
I’m relatively new to eloquent, and have problems loading data from a hasMany relation in an app that uses eloquent as the database layer. My (simplified) code is as follows: The SQL Schema is like below I then do the following query: This results in a json like the following Raw SQL query shows me that I do have data
Laravel query not using where clause for date
I have made a laravel query which gets all the data but does not use the where clause for $startdate. Without the start date working it just gets all the data which is not really the idea. Any idea how to fix? Answer Try this: