Questions tagged [laravel-query-builder]

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.

1522 questions
7
votes
1 answer

mysql_num_rows in laravel?

im trying to use mysql_num_rows in laravel but laravel says it not the same way like in 'raw php' example: $users = DB::table('users') ->where('username', '=', $username) ->where('password', '=', $password) …
indian
  • 75
  • 1
  • 1
  • 5
7
votes
3 answers

Using query builder for adding fulltext index in Laravel

This is the query for adding fulltext index in MySQL: ALTER TABLE `TableName` ADD FULLTEXT INDEX `IndexName` (`ColumnName`); But How can I use Laravel query builder to add fulltext index?
6
votes
3 answers

Laravel Eloquent - Merging two eloquent model results (not the collections)

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 current live qty (after things have been moved). Both…
Adam Lambert
  • 1,311
  • 3
  • 24
  • 45
6
votes
2 answers

How to write raw query in Laravel

I need to write a raw query in Laravel Database: Query Builder, That outputs size of specific table In core mysql query is as following SELECT table_name "Name_of_the_table", table_rows "Rows Count", round(((data_length +…
Hemant Maurya
  • 119
  • 1
  • 4
  • 13
6
votes
5 answers

How can fetching huge records using Laravel and MySQL?

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 using laravel and MySql? We are trying to follow…
6
votes
4 answers

Laravel - Trying to get property of non-object on ::first()

Ok so I'm getting Trying to get property of non-object when I try and get the data from the DB using $settings = AdminSettings::first(); here is the controller code
Yosef
  • 442
  • 1
  • 7
  • 26
6
votes
3 answers

get the request values in Laravel

I wish to make search query by datepicker and select field. How could I get the requests values from below view file to controller? Where could I modify in the code? thanks. index.blade.php
{!!…
6
votes
1 answer

I've assigned Laravel Query Builder to a variable. It changes when being used

it's a WHY-question, not How-to one:) I have assigned a Query Bulder to a variable $query: $query = table::where(['id'=>1, 'this_version'=> 1]); $versions['slug1'] = $query->select('tourist_id',…
Sergej Fomin
  • 1,822
  • 3
  • 24
  • 42
6
votes
4 answers

use distinct with multiple columns in laravel

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 …
HirenMangukiya
  • 645
  • 3
  • 13
  • 30
6
votes
5 answers

Using limit parameter in paginate function

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 response from paginate function will be all 100 users instead…
5
votes
1 answer

Passing a Closure with a variable to where method in Laravel query builder

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', '>', 100) ->orWhere(function($query) { …
Ayenew Yihune
  • 1,059
  • 13
  • 19
5
votes
1 answer

Laravel Many to Many Sync with additional column

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 instance, one user can belong to one team as a client and…
LoveCoding
  • 1,121
  • 2
  • 12
  • 33
5
votes
2 answers

directly increment or decrement number update from column using Laravel Eloquent

I have a query where in I use Eloquent for finding the ID but what I need is to directly subtract inside the eloquent query ? same as in Query Builder, Documentation code $flight = App\Flight::find(1); $flight->name = 'New Flight…
Martney Acha
  • 2,802
  • 4
  • 33
  • 48
5
votes
2 answers

Laravel: Merge two query builders

I have a table of courses which will be free to access or an admin will need to click something to let users see the course. The course table looks like this: | id | title | invite_only | |----|----------------|-------------| | 1 | free…
Djave
  • 8,595
  • 8
  • 70
  • 124
5
votes
3 answers

Laravel change date format in where clause to match Carbon::now()

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 luck. $now = \Carbon\Carbon::now(); $bookings =…
Klav
  • 405
  • 1
  • 9
  • 19