Sultenhest Sultenhest

Self Referencing Many-To-Many Relationship

Hello guys, I'm currently building a pseudo-Twitter clone using TDD for Laravel practice and i'm stuck building the "follow" functionality. As it is...
michapietsch michapietsch

Eagerly loaded relation not present in view

Hi, I load a model with with and first and in an immediate dump the related data is present, but in the data passed to the view it's missin...
fabricecw fabricecw

Reusing called accessor

I'm using an accessor which loads a custom relationship field: public function getHandoverDedicatedAreaAtAttribute() { $activity = $this->acti...

Names with special fonts saved as empty value

I observed that a few values of field 'name' aren't getting saved in mysql table and the values are as follows. What should be done to save these values? I tried to insert...
danyal danyal

Where clause on nested relationships in eloquent

Hi, I am working on a project where we are saving user's activity and his privacy settings. I want to get user's activity based on his privacy setting. So if user has set h...
hunterhawley hunterhawley

Order records by field, get record before or after any given

Hey y'all, I've got a model called 'Substitution", and it has a field called 'video_timestamp' which is an integer. I'm ordering them by this field, and cycling throug...
Chris1981 Chris1981

Retrieving information from 3 tables

I'm trying to get information from 3 tables in Laravel 5.8 but so far i have just come up with nothing. The 3 tables look something similar to the following;...
repulsor repulsor

Laravel Relations

Trying hard to figure this out. I have 3 tables. 1.Users (id,name) 2.Roles (id,role_id,role) 3.User_roles (id,user_id,role_id) User may or may not have...

Listen to *any* save/update/create event for *any* model?

I want to listen for any time a model changes, and I don't care what model it is. I don't want to have to set up a listener for every model, so I'd like to be able to just...
codeistalk codeistalk

Undefined property: Illuminate\Database\Query\Builder::$map

HI This is the first time I am dealing with API Resources in Laravel. I have create Resource Collection and using it's default definition. Changed nothing. Wi...
thebigk thebigk

Append an attribute to collection without causing N+1 issue

I'm trying to find out a way to append an attribute to the returned collection without causing N+1 issue. I've to fetch a list of events and the collection should ha...
andersb andersb

Conditional filtering on related model

I have two models A and B with a 1:n relationship and would like to find all B records where the associated A record meets a condition on B. Example: Get al...
KarthickZaigo KarthickZaigo

whereNotIn & where methods not working when combined

Eloquent query not working when I use both whereNotIn & where methods on single query....
littleboby littleboby

Illuminate\Database\QueryException : SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

Creating an application where people create events or 'meetups'. I created my factories: 2019_06_20162119_create_groups_table, (different meetup categories) 201906...
ExpDev07 ExpDev07

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'issuer' in 'field list'

Hey, I am trying to create a model through seeding but is getting the following error: Illuminate\Database\QueryException : SQLSTATE[42S22]: Column not foun...
michaelrtm michaelrtm

Using hasManyThrough through a pivot table

I am trying to create a relationship to access a table called comments through a model called grade, loaded through the students in the grade From my understanding,...
Dimitriz Dimitriz

Relation between two different database servers

Hi everyone, i have two different connections setup in Laravel, one mysql and other postgres in different sites. I can query the databases normally, but, one...
DerManoMann DerManoMann

Relationship from query?

Hi there, I've got this model method that I would like to convert into a proper relationship. Is that possible? Basically I want to convert the query into a Ha...
n0tttrui n0tttrui

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 {...

Returning the distinct results of Polymorphic relationship

I'm trying out spatie/laravel-model-status which creates a polymorphic relationship between your models and the status table. For example a post might be in one of a...
bwrigley bwrigley

Counting grandchildren

I'm looking through the eloquent documentation and I'm not quite finding what I woud like. hasManyThrough seems to be the closest but doesn't quite cut it....

Help me understand the problem with this hasOneThrough relationship!

I am building a simple application status tracker to be used by counselors. The relevant models here are as follows: schools -id students -id -...
adibhanna adibhanna

NeoEloquent - Laravel ORM for neo4j (GraphDB)

check this out guys! a great ORM for working with Graph DB, specifically Neo4J. you can use almost the exact syntax as Laravel's Eloquent....
timyboy12345 timyboy12345

Use a mysql connection in an Azure DevOps project

Hi there, I want to host a school project on Azure DevOps. I've got the laravel project up and running, but as soon as something needs to be gotten from the mysql da...
staticcode staticcode

Incorrect string value

Hi guys, this error is driving me nuts! I am trying to import CSV data. When I manually add it in Phpmyadmin then it works fine, but when I add it through Laravel I end up...
kdomagoj182 kdomagoj182

Model relations

When echoing $client->name in everything works fine, but when I tried to echo the same thing in results.create.blade.php Laravel throw error Undef...
vybeauregard vybeauregard

Eloquent Model Events in Laravel 5.4

In previous versions of Laravel, I was able to define an array of events and the listener action inside a trait which was then applied to several models in my app. In Larav...
keizah keizah

Multiple model updating

Hello, maybe there is alternative way to update couple model at once? $neighbours = Category::where('left', '>', $category->right); $neighbours->up...
kwojcik kwojcik

Problem with relationship hasOneThrough (i guess)

Hi guys, i have following tables and structure: table: Product - id - part_no - flow_id table: ProductStructure - id - part_no -...
aristain7 aristain7

Group by subcollection (belongTo relationship)

Hey i have this in my controller $all = $warehouse->with('category' )->where('WarehouseGroupID','=',$GroupID)->get();...
beeInteractive beeInteractive

Create a unique username based on first letter of first name and entire last name in Laravel

I have a database with users. One column for the first name, one for the last name. I need to generate the usernames based on the first name and the last name and need to f...
lambooni lambooni

Model observer seems to hang and run synchronously during each loop

I have the code: $model->each(function (Model $model){ dump('Gets here for every row of loop'); $model->doSomethingThatCreatesOrUpdatesAnotherM...

Laravel one-to-many on postgreSQL stops working

I'm using a one-to-many relationship in my code. It is working perfectly fine on localhost with: PHP 7.1.x MySQL (version unknown) Laravel la...
innerbot innerbot

Eloquent Help: Generating Attribute Values Before Creating Record

On my User model, I have several fields that need to be populated before the record is created. I don't think this can be done using the User::$attribute...
Create a New Discussion Button