laravel-query-builder Questions

2

Solved

Can anyone please explain in detail what Eloquent's Model::query() means?
Heated asked 25/7, 2018 at 10:55

16

Solved

How do I say WHERE (a = 1 OR b =1 ) AND (c = 1 OR d = 1) For more complicated queries am I supposed to use raw SQL?
Duisburg asked 8/6, 2013 at 1:29

22

Solved

I have two tables, User and Post. One User can have many posts and one post belongs to only one user. In my User model I have a hasMany relation... public function post(){ return $this->hasm...
Colorist asked 8/11, 2013 at 6:30

6

How to GROUP BY multiple column in Laravel? I tried this code: $routes = DB::table('route') ->groupBy('rte_origin') ->groupBy('rte_destination') ->get(); But this is not working.
Tunicate asked 20/4, 2014 at 17:23

6

Is there a way to get a table's primary key name using the Laravel query builder? Can i do something like $key = DB::table($someTable)->getPrimaryKey(); I've looked through the documentation...
Aesop asked 16/4, 2018 at 16:5

6

How do I flatten a collection with hierarchy self referenced models, tree collections into a single dimension collection. I have a self referencing model having parents and children. I want the re...
Basting asked 26/12, 2016 at 17:1

38

Solved

Given the following code: DB::table('users')->get(); I want to get the raw SQL query string that the database query builder above will generate. In this example, it would be SELECT * FROM use...
Searcy asked 14/8, 2013 at 15:43

5

Solved

I Need experts Suggestions and Solutions. We are developing job portal website here by handle around 1 million records. We are facing records fetching timeout errors. How can I handle those records...
Manilla asked 6/2, 2018 at 12:54

9

I'm trying to add a condition using a JOIN query with Laravel Query Builder. <?php $results = DB::select(' SELECT DISTINCT * FROM rooms LEFT JOIN bookings ON rooms.id = bookings.room...
Undercool asked 31/5, 2013 at 2:43

6

Solved

Here is how I am trying to paginate: $posts = Post::all()->sortByDesc("created_at")->pagination(1); But I get this error: Method Illuminate\Database\Eloquent\Collection::paginatio...

26

Solved

I'm using the Laravel Eloquent query builder and I have a query where I want a WHERE clause on multiple conditions. It works, but it's not elegant. Example: $results = User::where('this', '=', 1...
Cecilycecity asked 11/10, 2013 at 18:56

15

Solved

What's the shorthand for inserting a new record or updating if it exists? <?php $shopOwner = ShopMeta::where('shopId', '=', $theID) ->where('metadataKey', '=', 2001)->first(); if ($sho...
Footboy asked 17/9, 2013 at 1:34

4

Solved

I have a query that returns a boolean field (by the way, I'm on an SQL Server) on my REST API developed with Laravel and a few days ago it was returning the value as true/false, but now it returns ...
Clarion asked 19/11, 2019 at 16:35

4

my table structure is as below date seller unit price total 05-06-17 abc 14 700 9800 05-06-17 pqr 12 600 7200 05-06-17 abc 10 520 5200 06-06-17 abc 10 600 6000 06-06-17 pqr 15 520 7800 06-06-17 pq...
Krasner asked 6/6, 2017 at 5:58

3

Solved

I need to select entries based on dates happening in the future and the entries contain the date format: 12/30/17 I'm trying to format the date and compare to Carbon::now() timestamp, with no l...
Chondrite asked 29/12, 2017 at 17:29

5

Solved

I want to sort multiple columns in Laravel 4 by using the method orderBy() in Laravel Eloquent. The query will be generated using Eloquent like this: SELECT * FROM mytable ORDER BY coloumn1 DESC,...
Arela asked 9/6, 2013 at 4:5

3

I have a table of stock movements, which shows a history of a product (receiving, moving location etc.) I have two queries which calculate (via aggregate sums): The original received qty. The cu...
Vesiculate asked 17/4, 2019 at 19:46

3

Solved

In one of the my worker scripts to store aggregate counts based on some metrics, I am not using Eloquent as the queries are a little complex and and it is easy to write using query builder. I am cu...

21

Solved

How can I retrieve the raw executed SQL query in Laravel 3/4 using Laravel Query Builder or Eloquent ORM? For example, something like this: DB::table('users')->where_status(1)->get(); Or:...
Martinet asked 26/1, 2013 at 10:44

4

Solved

I created a query. I want to join my table with students table: $query->leftJoin('students', 'learners.student_id', '=', 'students.id'); But I don't know my table joined before or not. How sh...
Press asked 27/2, 2019 at 9:52

1

Solved

According to the Laravel documentation, an 'or' condition can be grouped by passing a Closure as the first argument to the orWhere method: $users = DB::table('users') ->where('votes', '>', 1...
Hereabout asked 3/9, 2020 at 9:15

4

Solved

I noticed that I write the database table names quite a lot, and in different files, when I use the Query Builder. If I were to change the database table names, I would have to search and change qu...
Halves asked 19/8, 2016 at 10:8

5

Is it possible to use 'limit' parameter in paginate() function? I'm trying this: $users->where(...)->limit(50)->paginate($page) ...and now, if I have 100 users in the database then the...
Alliber asked 18/4, 2017 at 13:32

1

Solved

Laravel version 7.0 I have Team model and User model, team_has_users table. team_has_users table has team_id, user_id, role columns. One user can belong to one team with different roles. For instan...

1

Solved

How can I addSelectRaw() in order to bind my variables to addSelect()? I've got this in my code: $query->addSelect( DB::raw('MATCH(matchy.val) against ("'.addslashes($q).'") as relevance ') );...
Piggyback asked 24/4, 2020 at 9:16

© 2022 - 2024 — McMap. All rights reserved.