in my Laravel app I have 3 tables : users, documents and type_documents, the user have multiple documents and document have one type_document I want select the types that are not used in documents table for the current user with eloquent I try with this, but it give me the used type_documents : I use Laravel version 8 Answer Have
Tag: eloquent
How to use CASE WHEN IN in Laravel database query builder
I have users table and a followers table. I’m doing a search to get all the users with a specific keyword, but I want the ones which are followers of the current user to appear first. I can get all the followers id’s in a subquery, so my idea was to do something like this: I’ve been trying to get
Laravel onDelete(‘cascade’) does not work
My Tables: I am getting following errors when I try to delete support_categories Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails Answer You just write foreign key in wrong order. Instead of: Write: or you can use casadeOnDelete():
Select from select using Laravel eloquent
I want to get all user’s favourite products. The query should be like this: How can I query with eloquent? Answer You’re trying to achieve something like this: In the oficial documentation you can find the explanation of Advanced where clauses The final result will be (you can see this dumping the query using toSql() method instead of get()) :
SQL query for last 365 days report
I have a reports table with the following structure : I want a SQL Query to get the report for the last 365 days by following conditions : Group dates if the same date is repeated. The days which the report is not available for the last 365 days, I need those days added to the result rows with 0
Laravel many to many relastionship count
I have two tables. User and days, with many to many relationship. user_days : user_id, day_id I want to get the count number of users in day_id = 1 {for a particular day} or something like this. Any way to get count from pivot table? This function didnot work. the table structure ? How do I find the user count
How to order by multiple columns not creating different groups using Laravel eloquent
I have a table which looks like this: Name AltName Sam null Ann null null Mark John null null Bart Sasha null I want to order by both Name and AltName. If I do this: This will return the data in this order: Ann, John, Sam, Sasha, Bart, Mark I don’t want it to group the data but instead merge
Laravel 8 Livewire search filter not working with first where clause
I want to have a table which shows all the data per company that has a filter search input, the problem is when I put the first argument where(‘company_id’, Auth::user()->company_id) it bugs out and doesn’t make the filter search work. This is my query for the table. Answer I suppose you want company_id filter to apply to all query and
How to select data using like with out consider after character in laravel or sql
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
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