Category "eloquent"

Laravel. Json column with cast as array are returning as a string when using JOIN in query

Laravel 8. I have two tables(models) 'employees' and 'positions'. In a model 'employees' I have a casts: protected $casts = [ 'academic_post' => 'array'

Laravel Model save() & update() Not Saving

Laravel 5.7 Hello I have been looking through stack overflow and have tried many possible answers and have come to no conclusions. I am updating a simple inte

Laravel empty pagination data

My query from Laravel Builder toSql() function. select `dispatcher_leads`.*, (select CASE WHEN lead_positions.order_type = 'shift' THEN DATE_ADD(lead_positions

laravel get error of Call to a member function prepare() on null

In Laravel I have got this error, while inserting a record in my MongoDB database. Call to a member function prepare() on null namespace App\Http\Controllers;

How to optionally call mutator in lumen

i use mutator in my model to encrypt id: public function getIdAttribute($value) { return encrypt($value); } but I want the default value to be the original

How to update the timeout field in the attendance table for a given user_id, logdate and status using if else statement?

I have been trying to update the timeout for a given user_id, logdate, and status but my update statement is not working or may be my other if else are not corr

Laravel having column name in where clause static method

Recently I just realized that Laravel generates a static method with column name when joined in a where clause using camel case example $user = User::whereN

Laravel Eloquent relationships with 3 Table

Laravel 3 Table table_user id name table_barang id iduser name statusbarang_id table_statusbarang id name My code UserModels: public function BarangModels()

Laravel SQL query midnight time not showing

I am making a schedule display system and it shows the schedules of ferries. my problem is if I dont put midnight time in order then query skips midnight time a

Laravel mongodb where array field contains value

I use mongodb and mysql together with Laravel. Fields table in mysql database can have more options in mysql database. fields table in mysql: id, name options

How to order by eager loaded relationship in Laravel 5.5?

The code below works perfectly and displays all products with discounts in JSON Format for my API. But I want the result ordered by id in the discounts table. S

"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(