Category "eloquent"

"RuntimeException: a facade root has not been set"

I'm having an issue in a Laravel Zero project I'm working on. I'm working on a command that handles direct file transfers between 2 disks—1 SFTP and anoth

Laravel get rows with created_at not older than 24 hours

I need to get all the rows on my database that meet some criteria. One those criteria is to not be older than 24 hours. I've been trying different solutions pos

Issue with laravel eloquent model property

I'm trying to print {{$day->date}} in a view. Instead of full date YYYY-MM-DD the property only returns year YYYY. Can anyone explain me why it is working li

The post method is not supported for this route

I'm new to laravel and I want to submit a form which have three attachments plus some arrays but when I click submit button laravel says "The POST method

How to insert data in the enum field?

I've an enum field in my migration. The code is here: Schema::create('clients', function (Blueprint $table) { $table->increments('id'); $ta

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

I'm struggling to sort an Eloquent collection using the sortBy() method. The issue is that the sorting is case sensitive and it first retrieves the uppercase re

Is there a way to use the same parameter into multiple place in the same query with Eloquent? [duplicate]

I am working on a Laravel 5.7 based project in which Eloquent is used as an ORM. I need to execute a raw SQL statement on my database. Howev

Unset/Remove relation object from Laravel Eloquent collection

I've a fetch a Laravel Eloquent collection by: $product = Product::query()->with(['merchant', 'picture'])->where('id', $id)->first(); and get the du

Laravel Eloquent get() indexed by primary key id

I often find it very useful to index my results by the primary key id. Example: $out = []; $users = User::where('created_at', '>=', '2015-01-01')->get(

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