Category "eloquent"

Eloquent ORM and relative where time statement

I'm using ORM Eloquent and I need to filter all models using a date interval and an own property of the model. The raw SQL would be: SELECT * FROM model WHERE s

Laravel Many To Many Get element that I dont have a relationship with

In laravel Many to Many relationship like the one in the Laravel Documentation example. https://laravel.com/docs/9.x/eloquent-relationships#many-to-many users

Submit data to database using Inertia/React in Laravel

I have a form that is supposed to submit order details to the orders table through a custom select element (headlessUI Combobox). The element works fine but I c

How to log every query from multiple connections in Eloquent (outside laravel)

I use multiple database connections in my app, one SQLServ, and another MySQL. I want to debug every query from both servers sequentially. therefore rather usin

How to include model attribute automatically?

I have the User model which define the following attribute: public function getAvatarUrlAttribute() { return 'https://i.pravatar.cc/300?u=' . $this->

How to show monthly wise data in Laravel 8

I've posted about this three times and hopefully someone will help me with a solution. I have a lot of data in my database that the user has created. Suppose I

Laravel livewire sorting by foreign key

I'm trying to sort a post table by a foreign key, and can't figure out how to do it. Hopefully someone can lend me a hand. I can sort by the fields already pres

How to use regex or any other operator with whereIn clause

Is there any way we can use operator or regex as we normally do with the whereIn() clause. I want to use something like this $query->whereIN(name,'like','%te

renameColumn migration fails for existing column with columns does not exist error

I get the error Doctrine\DBAL\Schema\SchemaException : There is no column with name 'price' on table 'class_rooms'. while running migration to rename the price

Get all the products which are inside parent Category and child categories in Laravel with the help of relation

I have category and product table as follows: Categories: id | name | slug | parent_id Products : id | brand_id | name | slug | price | desc P

Laravel Polymorphism for different content types (Multisite)

I started to develop a little Content Management System for two languages (de, en) that starts to grow bigger. In that context, I have Posts and Pages (a bit li

Laravel 8 eloquent query delete

How to delete the aircon in database when there is no any data. Order and Aircon are many to many relationship. $orders = Order::with('aircons', 'user')

Laravel eloquent query with filter "where ILIKE" does not match with any value with accent saved in my Postgre database (encoded in UTF8)

I have a Laravel 5.8 app. It works with a Postgres Database encoded with UTF8. I have a query for my users table, so i made my query as: $users = User::where

Sync Records With Default Values in Pivot Tables, Call to undefined method syncWithPivotDefaults()

I just upgraded laravel 7 to laravel 8.30.1 and I am trying to add the default value of pivot column object_model of term_relationships table using the newly in

how to use whereHas in laravel

I am new to laravel, I need to create a query for the db, $query = Deal::query(); I want to use the wherehas operator. this is my code that is worked. else if

One eloquent query with whereIn clause with more than 3000 elements works but another one with the same elements and format doesn't

Hello and thank you beforehand for your help. I've been hitting my head against a wall with this problem for a few days now so decided to ask here. I have two q

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;