Category "eloquent"

Laravel 5 issue with wherePivot

I am working with Laravel 5 and I am having issue getting ->wherePivot() to work on a Many-to-Many relationship. When I dd() the SQL it looks like Eloquent i

How to Make Laravel Eloquent "IN" Query?

I want to make query in Laravel Eloquent like here its raw MySQL query SELECT * from exampleTbl where id in(1,2,3,4) I have tried this in Laravel Eloquent

Laravel how to get query with bindings?

I have some query that I need to pass to another query using query builder $query = DB::table('table')->whereIn('some_field', [1,2,30])->toSql(); Model::

Laravel Eloquent query with optional parameters

I am trying to learn whether or not there is a simple way to pass a variable number of parameters to a query in Eloquent, hopefully using an array. From what I

How to get monthly wise data in laravel

I have a lot of data. I want to bring the data from the database as a monthly wise. I have already used group by method but when I want to view the data all the

Laravel attach pivot to table with multiple values

Background I'm creating a database revolving around food allergies and I have a many to many relationship between foods and allergies. There is also a pivot va

Reducing authentication calls on external API (Laravel 5.6)

My app requires data to be gathered from an external API. I am using Guzzle. My API methods are written into a separate class stored in a library folder. I ha

Laravel Eloquent vs DB facade: Why use Eloquent and decrease performance? [closed]

I did some performance tests between Laravel's DB facade query builder and Laravel's Eloquent ORM. The DB facade was much faster than Eloquent

How to join on a select result with eloquent in Laravel?

I want to join on a result of other select like this : SELECT * FROM TABLE1 JOIN ( SELECT cat_id FROM TABLE2 where brand_id = 2 GROUP BY TABLE2.cat_id) A

Natural ORDER in Laravel Eloquent ORM

How can i get 'natural order' in 'Eloquent ORM'? In table I have column 'text' (string). Normal order: Model::orderBy('text') 'value 1' 'value 12' 'value 23'

Laravel: Select first record in a One-to-Many relation

Is it possible to use eloquent to retrieve just the first match in a one to many relationship? What do I mean, well, let me explain. Most of us are familiar wit

Querying only one row from a one to many relationship laravel

I have a products table and a product_pictures table, where a single product can have many pictures (one to many relationship). I am trying to display all of th

Querying only one row from a one to many relationship laravel

I have a products table and a product_pictures table, where a single product can have many pictures (one to many relationship). I am trying to display all of th

How to return database table name in Laravel

Is there a way that I can get the current database table in use by the model that I'm in? I see that there is a table() function in Laravel/Database/Eloquent/mo

MySQL order by field in Eloquent

When I want to define a custom sort order in a MySQL query I can do something like this: ORDER BY FIELD(language,'USD','EUR','JPN') What would be the Eloquen

Laravel eloquent update record without loading from database

I'm quite new to laravel and I'm trying to update a record from form's input. However I see that to update the record, first you need to fetch the record from d

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

I have a pivot table that connects users to workspaces. On the pivot table, I also have a column for role, which defines the users role for that workspace. Can

Remove categories with all childs derived from parent category

I want to remove all related child categories from parent categories. I think I need a recursive function to solve this. Here is my attempt: public function de

Return new collection without modifying original collection

I have a Laravel collection and I want to modify one of its property value to negative integer. For this I am using the collection map method but it also modify

How to make a migration in laravel module?

In my Laravel project, I use nwidart package for making modules. Now I want to add deleted_at column to an existing model. I should make a new migration in my m