php - Laravel relation problem after update to version 6
one text
i updated laravel version from 5.6 to 6 one week ago for implementing new things on my API, problem is after the update one of my relations just broke. At certain point after login i need to retrieve some info based on who is connected, on a 3 level relation (cme_permissions.subcomisionData.members) and it brokes on second level (cme_permissions.subcomisionData), i looked at this using dd() step by step. I'm just starting into this world of programming and i don't know what the heck is happening, thanks for the help.
Query:
User::where('id', Auth::user()->id)
->with('cme_permissions.subcomisionData.members')->get();
First relation (User):
public function cme_permissions() {
return $this->hasMany('App\CME\CMEPermission');
}
Second relation:
class CMEPermission extends Model
{
public $table = 'cme_permissions';
public function subcomisionData() {
return $this->belongsTo('App\CME\CMESubcomision', 'subcomision');
}
function user() {
return $this->belongsTo('App\User');
}
}
Third relation:
class CMESubcomision extends Model
{
public $table = 'cme_subcomision';
public $incrementing = false;
public $timestamps = false;
public function members() {
return $this->hasMany('App\CME\CMEPermission', 'subcomision')
->with('user');
}
}
This still works on my pre-version before the update so i don't know if the problem is with the dependencies in composer.json or what, whatever here it is: Composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "6.0.*",
"laravel/passport": "^7.1",
"laravel/tinker": "^1.0",
"league/csv": "^9.5",
"elibyy/tcpdf-laravel": "6.0.*"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.6",
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^7.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
}
}
Edit: It doesn't display any error just a null on the second relation
#relations: array:1 [
"cme_permissions" => Illuminate\Database\Eloquent\Collection {#469
#items: array:1 [
0 => App\CME\CMEPermission {#466
+table: "cme_permissions"
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:5 [
"id" => 2
"user_id" => 1685
"email" => "PRU_0004@mail.es"
"subcomision" => "1.1"
"cme_role" => "Vocal"
]
#original: array:5 [
"id" => 2
"user_id" => 1685
"email" => "PRU_0004@mail.es"
"subcomision" => "1.1"
"cme_role" => "Vocal"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [
"subcomisionData" => null
]
Source