1
I have the following model, using Laravel 5.8
I ran all the records and structured the relationships. On my Dashboard I need to list in card form all reports from a specific user. How could I do this?
So far I can get all of that user’s groups doing this:
$obj = User::with('grupos')->get();
However, how can I access the other table and get to the report? I tried to do something like this:
$obj = User::with('grupos', 'relatorios')->get();
However, the relationship is in another table can not list the data
User model
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password','cliente_id'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function cliente()
{
return $this->belongsTo('App\models\Cliente');
}
public function grupos(){
return $this->belongsToMany("App\models\Grupo", "acessos");
}
}
How’s your user model class?
– Ismael SIlva
edited in the main question
– XLannes