The database query builder provides a convenient, fluent interface to creating and running database queries in Laravel apps. It can be used to perform most database operations in your application, and works on all supported database systems.
Questions tagged [laravel-query-builder]
1522 questions
-1
votes
1 answer
Filter query not working through Laravel query builder
I have a filter query where it checks for three parameters id, keywords and status. It's working totally fine when I run this query in MySQL but when I try to run it through Laravel's query builder it's fetching all the results of that id.
Here is…

Saud
- 859
- 1
- 9
- 23
-1
votes
3 answers
Laravel query format - Join To the Latest row
I have two tables for example users and orders.
I have to join users with orders On users.id = orders.user_id - which is quite fine.
User table has one to many relation in orders table.
I have some conditions also, like orders.pay_type = 'xyz',…

Sangeetha
- 167
- 1
- 10
-1
votes
2 answers
leftJoin with same table return more records than expected (Query Builder)
I have created a query to fetch data to return to a view.
Query should return 8 records but instead returns 10 records. One order is wrongly replicated 3 time.
I could find out that the 2 following leftJoin with the same table are causing this error…

marcq
- 477
- 3
- 12
-1
votes
1 answer
Is there any other way to do filter with laravel query builder?
I am doing filter for displaying data and the code are getting longer since I use if else clause for every possible condition. Is there a better way to write these code?
This is one of the example code that I use on filter.
HTML code:

Qi Yang
- 69
- 1
- 12
-1
votes
2 answers
Laravel update key and value in database
i have key and value columns in db how can i update them from controller ?
How Can i update by key
$settings = \App\Setting::where('type','synrisk')->get();
$settings->fill($request->all());
$settings->save();
Session::flash('message', 'تم التعديل…

Kareem Elsharkawy
- 429
- 5
- 17
-1
votes
1 answer
Query builder proper sintax for 4 joins + 3 where clauses (Laravel5.7)
I'm trying to get this MySQL query to work in laravel 5.7 query builder.
It works fine in phpmyadmin
SELECT c.Symbol
, s.SectorName
, cprs.strenght
, s.parentid
, ssbpi.Risklevel
, ssbpi.ColumnType
FROM Companies AS c
JOIN Sectors AS s ON…

gallo2000sv
- 111
- 1
- 2
- 12
-1
votes
2 answers
How to Convert SQL to Laravel Query
I want to build something with an aliases column like below, but I don't know how to make it a Laravel query. The following is my SQL.
SELECT
d.*,
d.damaged_building,
d.total_victim
FROM
(
SELECT
delete_flg,
…

Faisal Tanjung
- 31
- 5
-1
votes
1 answer
How to convert this sql query into laravel query builder?
I had a table(itemregistrationpangkat) with name(joined from other table itemregistrations), negeri(joined from other table named negeri) and year of start service and end service. I want to get the number of years a person served in a state:
ID…

joun
- 656
- 1
- 8
- 25
-1
votes
1 answer
Left Join not working as intended yet SQL accepts it
HomeController.php
public function index()
{
$employees = DB::table('timings')
->distinct()
->selectRaw("timings.employee_id, min(time_logged) AS minTime, max(time_logged) AS maxTime")
…

Nazar Abubaker
- 495
- 3
- 7
- 17
-1
votes
3 answers
"Trying to get property 'id' of non-object"
I want to get the id of the cycles table so that I can store to the mortalities table.
SELECT `id` FROM `cycles`
WHERE `date_start_raise` <= request('date_input')
AND `date_end_raise` >= request('date_input')`
Converted to Laravel Query…
user9085254
-1
votes
1 answer
Laravel : How to hide user's own profile from friend list?
There are three tables: users, profiles, friend_request
profiles table's column : profile_id, id (foreign key with users) , first_name,last_name
friend_request's table column : request_id, sender_id,to_user_id, request_status
logic : if profile_id…

Entrepreuner
- 53
- 4
- 11
-1
votes
3 answers
Save custom timestamp column to db after the row has been created
I have a table in my db that includes a nullable timestamp column.
$table->timestamp('custom_timestamp')->nullable();
When the row in the db is created this column will be null. Later when the user does this specific thing I want to update this…

Brainmaniac
- 2,203
- 4
- 29
- 53
-1
votes
2 answers
Call to undefined method Illuminate/Database/Query/Builder::toArray()
I am new using laravel, and I got this error like this :
Call to undefined method Illuminate\Database\Query\Builder::toArray()
this is query builder in laravel
$statsMoneyInPlay = DB::table('enginepoker_log.poker')
…

Muhammad Romi Muhtarom
- 21
- 1
- 4
- 9
-1
votes
1 answer
Laravel queryBuilder (5.6)
Hello I'm trying to replicate this SQL code into Laravel qBuilder but I'm not getting the result I want in the collection:
select chars.name, class.name, specs.name
FROM characters as chars
JOIN charclasses as class
JOIN charspecs as specs
WHERE…

Federico Ballarino
- 11
- 4
-1
votes
1 answer
How to calculated grade then pass to blade template
I have table named SCORE which has column name Result,i want to apply grade computation based on the value from RESULT like this
if('result'>=90)
{grade=A+}
This is my grade conversion
90% to 100% (A+),80% to 89% (A),70% to 79% (B),60% to 69%…

Grace
- 299
- 2
- 6
- 28