i have function in my controller that create a forecast : As you can see i use updateOrCreate methods to add or update a forecast. The problem is when 2 requests from the same user run at the same time (and no forecast is already created) 2 row are inserted. Do you have a solution ? I See that the
Tag: laravel
How do I convert SQL statement with alias in a valid Laravel query builder?
I am working on a Laravel 8 application. I have the flowing SQL statement containing the alias country for the column name of the countries table: I have used this online tool to convert it to a valid Laravel query builder. The problem Unfortunately, the result (visible below), ignores the alias and displays the colum as name instead of country:
Many-to-many relation Laravel Eloquent. Fetch related table with specific related id
I am writing a query in Laravel 8 using Eloquent. There is a many-to-many relation between subjects and streams and their pivot table is courses. subjects: id name streams id name courses id subject_id stream_id I have to fetch subjects with specific stream. I have written the following query. $this->subjects = Subject::has(‘streams’,$this->stream)->get(); I am having problem in this. courses table
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
Slow Querying DB
I am currently optimising a system with many connected tables. The part that I am working on right now is displaying table orders. The problem is that in this table there are also many relations (around 10) which I am querying. The problem itself is in querying that many relations. I have been using Eloquent + with() methods for eager
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
MySQL remove zeros from decimal part if the number is whole
I have a sales table with price column as decimal(8, 2) and I’m running the query below to get the total price It’s working perfectly but my results are usually intergers so I end up with trailing zeros all the time. It’d be nice to just return the whole number if there is no decimal part Answer like akina said
How to convert SQL query in laravel query?
I know this question is not asked in a well manner way,so I am sorry,I have SQL query this one I want to convert it in PHP laravel query form so tried this query but I don’t know SQL and even I am not understanding how I convert it, can someone help just convert SQL query to laravel query? here
Query DB Laravel
I’m trying to count the post count of each tag, then orderBy by the post count. But there was a problem when counting the number of posts: tags with no posts were not displayed. I want if any tag has no post, it will still be printed. What should I do. Answer you can use LeftJoin to show all rows