rjruiz rjruiz
11

How to return JSON response from a query with eloquent?

I am working on this query: (I wish I could pass this same query using eloquent and return a JSON as response.) public function getChart(Req...
Eloquent
11
130
burimb burimb
5

Get all relationships of relationships !!

We have a table a project that have many milestones and each milestone have many tasks. How to get for each milestones all tasks and get onlt...
carpad88 carpad88
4

Get column names from table

I want to retrieve all the column names from one table in my DB, I've used this code and it works $headings = DB::connection() ->getSc...
PabloT PabloT
2

Laravel 5.5 query (sub-query) pluck.

Hi, Please, I have: Laravel v5.5.48 Tables: ads ad_settings special_sections table: ads...
mstnorris mstnorris
12

Model sortBy relationship count and paginate results

I have two models; Establishment and Signature. An Establishment hasMany Signature. In t...
Eloquent
12
1265
JohnEC JohnEC
1

How to return JSON response from a query with eloquent?

How to return JSON response from a query with eloquent?...
JeroenVanOort JeroenVanOort
6

Set default JSON date format

Dear Laravel enthusiasts, As I have asked before I like to format the d...
hunterhawley hunterhawley
3

Difference Between Queries?

Hi there, I was wondering why these two queries are returning very different counts? Version 1: $collection = BasketballGameEv...
madsynn madsynn
2

Easiest way ??

I have a create page that includes the data from 4 other crud in the same page and im looking for the easiest way to store them. On store do i need to seperate the f...
jenya jenya
13

Print nested hasMany relation

Hello! I use Laravel 5.8.35 with php 7.3.5. I have three models: //Card model <?php namespace App; use Illuminate\Database\Eloquent\SoftDeletes; use Illu...
Eloquent
13
441
packy packy
12

relationship groupBy in initial query

I am trying to groupBy a relationship in the initial query from my controller but not having such luck. For now I have a workout, but seems clunky:...
yassineqoraiche yassineqoraiche
20

Eloquent get data using last relation value

Hello everybody, I have two models, user, and books the last one has a status column that can obtain different val...
Eloquent
20
295
Constantinff Constantinff
3

BelongsToMany using Pivot class and multiple db connections

I have two models: Article belonngsToMany Images and the relations looks like that return $this->belongsToMany(Image::...
javediq_143 javediq_143
4

Multiple Polymorphic Relations in same Model

Hello All, Continuing with my Ecommerce site where users can order food online, I'm stuck at another stage. Below are the tables in my app: // users...
engrlaravel engrlaravel
8

select all records where due_date = tomorrow

I want to select all records who is expiring tomorrow. I have due_date (Y-m-d H:i:s) format, $tasks = Task::where('deleted_at', null) ->where('...
geek123 geek123
1

filter and sort model by computed attribute in a related model

I have these models: Product (id, sn, shop_id) Shop (id, name, latitude, longitude) How to get list of products sorted by distance where:...
hunterhawley hunterhawley
1

Variable Class Names or Secondary Table?

Hey y'all! I have a table, 'basketball_game_events', and it is full of, you guessed it, all the things that happened during basketball games (assists, rebounds, etc....
scottsuhy scottsuhy
3

Beginner: Having trouble understanding how to extract the data out of a result from a query.

I am new to Laravel/Eloquent and I'm having trouble understanding how to extract the data out of a result from a query. I'm calling the following query in the contro...
bngaard bngaard
1

Beginner: What is the best way to get data from multiple tables without duplication

Hi, I am fairly (few days old) in the world of Laravel, so I need some guidance as I do not quite understand the how to use the model and Controllers quite yet....
SdeWijs SdeWijs
0

ISO8601 date serialization in Laravel 7

I noticed that Laravel does not cast all timestamp columns to the ISO8601 format out-of-the-box. If I return a model (in response to an Ajax request), which is converted to...
waclaw66 waclaw66
2

Order by multiple columns from different tables

Hello, could you please help me to build the following query? Let's assume relationships: Group has many Members and Member has one User. Member has attribute...
Thavarshan Thavarshan
1

Count items per day in week

Does anyone know how to group data by week like for instance, all posts created during the period of the last 7 days starting from Sunday?...

Eloquent how to group data by an row

I have the following table: id type title -- ------ ----- 1 1 title-1 2 2 title-2 3 2 title-3 4 2 title-4 5 1...
Eloquent
4
3392
DoeJohn DoeJohn
1

Laravel Many-to-Many (on the same users table/Model): Query scopes to include related for the specified user

Users can block each other. One user can block many (other) users, and one user can be blocked by many (other) users. In User...
mstdmstd mstdmstd
1

Why Rollback raise Cannot drop index error?

Hello, in my laravel 5.7 app I need to add table and reference in other table to created table. I made 2 migration files and migrate command runs ok but running roll...
FutureWeb FutureWeb
8

Update multiple records using Eloquent

Hi LarPeeps, How can I update multiple rows with a single query like: $update = mysql_query("update item_table set colour = 'black' where item_type_...
Eloquent
8
22887
kingmaker_bgp kingmaker_bgp
5

Eloquent whereHas Relationship with constraint on particular related Entity

Hello Web Artisans and Laravel Enthusiasts, I had a very interesting and challenging question whi...
Mikegk Mikegk
4

Update Eloquent Data

Hi Guys, within an model (UserStatus), I have the following method: private static function getUserStatusById($id_user,$select='*'){ return Us...
isadma isadma
6

Laravel collection

I have this kind of collection. { { id: 125, name: "John Doe", cars: [ { model: 5, type: 2, address: { address: "St...
isadma isadma
3

filter collection

{ { id: 125, type_id: 123, apartments: [ { id: 132, user_id: 32, floor: 28, }, { id: 133, user_id: 32, floor: 29, } ],...
jerauf jerauf
2

Delete all but the first 50 rows in a query

I want to keep only the first 50 rows that are returned by a query. I tried using skip(50) but that didn't work. Any ideas?...

User Activity Log

Greetings, I have two database tables users and activity_log with dummy records as below: Table users id...
nolros nolros
2

Nest model $with is making 3 queries

Workspace database Schema::create('workspaces', function (Blueprint $table) { $table->bigIncrements('id'); $table->unsi...

Eloquent changes in laravel framework 7

I get question about the function in vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php: in elder version, the function returns $da...
karateka karateka
0

Or where exist in the same table

Hi, I have problem with my eloquent query. Now I have this code: $comments = Comment::where(function($q) use($search) { $q->where('content...
Create a New Discussion Button