Prabodhana Prabodhana
3

get details using foreignkey using another table foreginkey

I have three tables in my database tbl_universities [id, code, name, country] tbl_programs [id, tbl_university_id, program], tbl_batches [id,...

Trying to change model Id name so calls the right column

I'm getting this error SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bids.auction_id' in 'where clause' (SQL: select * from bids where b...
Sato_shi Sato_shi
3

Modify model data in 'created' event

Hi All! Is it possible to modify model in 'created' event? I wrote in Model: public static function boot() { parent::boot(); self::created(functio...
jesse_orange_newable jesse_orange_newable
9

Understanding the hasManyThrough relation

Hi everyone, I'm trying to understand a relation I haven't paid much attention to, until recently. In my setup I have 3 models: Team, User...

Eloquent 3 dimensions pivot table

Hi, So today I had an headache on a 3 dimensional pivot table. Working with eloquent in a simple two dimensions pivot table is really easy but once you want more, re...
jorisvanandel jorisvanandel
1

Eloquent: opposite of sum

I want the opposite of Model::sum('property'); So that it doesn't add but instead subtracts the property of all models....
vikas_developer vikas_developer
17

Eloquent Relationship help

I have three tables : User => [ id, email, password, timestamps ] extra_orders => [ id, user_id, order_id, quantity, status, timest...
Eloquent
17
725
royo1987 royo1987
3

Double relationship between two tables

Hi, I’ve this problem: I’m using Laravel 5.7, I have two tables: Schema::crea...
el0zahaby el0zahaby
5

how to get all user activity [likes,comments] from his posts

Hello, so I have an application in Laravel in which a lot of user data is stored in separate tables across several models. I now have a requirement to create an activity f...
danimohamadnejad danimohamadnejad
1

how to first row with loweset value of a column?

Hello I would like to find first row from following table which has lowest sold_count: products id name sold_count 1 p1 20 2 p2 100 3 p3 20 4 p4...
tarraq tarraq
4

Parallel eloquent calls

Is there a way to dispatch two independent database calls in parallel and not return the request before both finishes ? I’m thinking similar to an API gateway, but...
Aronaman Aronaman
1

hasManythrough relation Database seeding

i have 3 table country, org, room. i made hasManythrough relationship. //country model public function rooms() { return $this-...
DennisHermannsen DennisHermannsen
4

Rewrite SQL query

Hello. I'm trying to update some old code we have. I need to rewrite the following query: SELECT DISTINCT tblclients.id,tblclients.firstname,tblclients.lastname FROM...
nanadjei2 nanadjei2
3

Query filter by relation

I am creating an application where a building has facilities and I want to make a query to get a building where its facility can be, for example; ["stand-by-generator&...
skoobi skoobi
8

Eloquent query to find specific number

Hi. I'm struggling to find out how to find a number in a database column. I've got a set of numbers which are saved in a column like so 3,6,12,34,56...
myke2424 myke2424
1

Filling up a bootstrap table with sql data

Hey, I was wondering how to do this: I have a table built in boostrap that looks like this:...
MattB MattB
13

Order By not working

What have I done wrong here? Is it how I've strung the query together? I have the below query: $companies = Category::all()->groupBy('company')->Order...
Eloquent
13
670
edalzell edalzell
1

Retrieving/calculating Order total from OrderItems

I'm new to Laravel and trying to understand best practices as I build an eCommerce system. Note, I'm on L5.1 atm, moving to 5.7, so solution must work on 5.1 right n...
edalzell edalzell
1

Query scopes or new model for self-reference?

I have a User that has a trainer_id, that is the id of another user. I'd like to be able to get all the Trainers. Does one normally create...

To pivot or not to pivot

I am fighting a lot with eloquent setup of my tables and models. I need to make a design decision before I continue coding. I have read many articles but I can't find any s...
myke2424 myke2424
8

How can I querie months and dates?

I'm new to laravel and not really sure how to do this. I record dates in my database as 'start_day' in my times table. an example entry will look like: 2019-10-03...
davestewart davestewart
12

Is there a way to (automatically) list all relations of a model?

Something like $model->listRelated()? I assume not as relations are encapsulated inside methods. My second assumption is that this means I sim...
Eloquent
12
656
n0tttrui n0tttrui
20

Select movies where category...

I have rather a category system: #Movie.php (Model) <?php namespace App; use Illuminate\Database\Eloquent\Model; class Movie extends Model {...
Eloquent
20
627
mostafalaravel mostafalaravel
3

How to check if sync pivot has different values ?

Hello , how to check if the sync is dirty? I would like to create a log only if there is something changed . public fun...
Eloquent
3
1072
AndySong AndySong
9

Lazy Collections working with DB

Route::get('/test', function () { $users = User::all(); return 'done'; }); I understand that if I have many User rec...
patrykszady patrykszady
8

whereHas latest child equals a value

Hi all, Besides my problem, I'm really struggling with queries / Eloquent ... any pointes to good tutorials? (summing ->groupBy , etc). I have a Project(ha...
TheeShot TheeShot
4

Eloquent Relationship advise

Hi, I am a newby with Laravel, but loving it! So now i am exploring the possibilities and i came across an issue. I want to try and build a time schedule subm...
whoisthisstud whoisthisstud
4

Get relationship from array of ids

I have two models - Projects and Assets - of which I store an array of related Asset id's. In my Projects create form, I list Assets as checkboxes which I then store...

Cannot add foreign key constraint - but why?

Hello everybody, I got this table schema: public function up() { Schema::create('cars', function (Blueprint $table) { $table-&...
dylanryan dylanryan
10

Query gets extremely slow

private function getArticles() { $query = Article::orderBy($this->sort, $this->sortOrder); if ($this->searchTe...
Eloquent
10
626
mostafalaravel mostafalaravel
10

model update: how to check if there is changes ?

Hello I would like to know if there is a way to check the data in model update before saving, For example in my controller I want to save() only if there is s...
Eloquent
10
1138
AnnBooney AnnBooney
2

MySql to Eloquent

How would I convert the above MySQL raw query to Eloquent query? "Select codigo, referenciacliente, nombre, nombrecliente, diasaviso from articulos where (artic...
Prabodhana Prabodhana
3

Get Foreign key details

i have two table university table and program table.. In program table has foreign key 'universityID'.. I add the relationship between this to in program model has "b...
Eloquent
3
1089
Aronaman Aronaman
11

Assign relationship for specifi user role

I have refund tables 1 to Many relation with user admin role. I have users table the question is how to assign for specif role in the model I try this ... //u...
Eloquent
11
992
Create a New Discussion Button