Skip to content
Advertisement

Tag: laravel

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

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

Advertisement