I’m a newbie with Laravel, but old school PHP developer. I’m in the process of adapting my framework to the Laravel framework. My main goal at this moment is to use eloquent queries without doing a DB schema and migration inside Laravel, as I have my database is built already, up and running. So far, I’ve been successful in using
Tag: eloquent
laravel write multiple where clause to filter files
I don’t know how to filter this in my laravel 9 app using eloquent. I am having a files table and file_metadata (pivot) – where files has multiple metas: ex: file_metadata for 3 files: So files 5 ,6 ,7 have 2 metas (3 active, 6 signed). File 7 is active but not signed. How to write the where clause to
Eloquent relationship where not in sub-query
I have got a relationship where I select all row’s based on the category, however I need to exclude some of these if they are within a sub query. So above is my code, nearly works as I want it, however it seems that the $q variable doesn’t have the table name within the query, below is the query outputted:
Laravel, search exact same substring in eloquent query
I have a table like this Teacher Table What I am trying to do is to get the row which contains the subjects 1(or any other number like 7,8 etc.) This is what I have tried in my controller. The problem here is that, I am getting all the rows which contains subjects as ‘1’,e.g. if it is ‘3,11,22’ or
Select the distinct latest records based on their creation date
How can I select, preferably using eloquent laravel’s query builder, the latest distinct records from a table. I have tried this query without success. Answer The solution was to use This ensured that the distinct returned only the unique latest record of each value.
IlluminateDatabaseQueryException SQLSTATE[HY000] [2002] No such file or directory but migrations works [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago. Improve this question first time I ask via the web, but I don’t know what I can do anymore. My question is about
Laravel 8 – Listen to eloquent events made during a specific request
Currently, I’m trying to wire a telemetry library (OpenTelemetry php lib) to the Laravel event model. The idea is to forward traces to a third party service. A single trace consistents of a request and all database calls that have been made during the request. I’ve created three middleware components: BeforeRequest: starts a trace OnRequest: call event listener which listened
Laravel Eloquent query siblings in same table with eager loading
I have a parent table called patients which has a one-to-many relationship with a child table called notes. (i.e. One patient can have several notes). If given a note, I would like to find other notes for the same patient. Notes are related to patients by a fk called patient_id. In SQL, I’d do this: SELECT * FROM notes WHERE
Laravel 8 eloquent query delete
How to delete the aircon in database when there is no any data. Order and Aircon are many to many relationship. Answer try whereDoesntHave Edit: You can also add new column aircons_count will old number of aircons for every order which will be faster than the above query and run the query like the following: Note: make sure to add
how to use Laravel 8 query builder like eloquent for searching
I’m developing a simple CRM with Laravel 8 that needs to search in query string. My query string would be look like: Now the problem is how can I search in controller? I want to do like this: I wonder why its not working and what is the standard way to do this. I’ve tried: but that didn’t work either.