Skip to content

Tag: eloquent

how join laravel tables to get non intersected data

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 …

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():

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

Delete unused groups in Laravel 8

I have a group model and I want to delete groups that don’t have any member. How can I get empty groups with eloquent or SQL query ? And this is the User model code: Answer I think whereDoesntHave work in you situation.