You need to configure both models
with the relationship of 1:N
(1 for many):
Plants
class Plantas extends Model
{
protected $primaryKey = "ID";
protected $fillable = array('Nome');
protected $table = "plantas";
public $timestamps = false;
public function users()
{
return $this->hasMany('App\Users', 'planta_id', 'ID');
}
}
Users
class Users extends Model
{
protected $primaryKey = "ID";
protected $fillable = array('Nome','planta_id');
protected $table = "users";
public $timestamps = false;
public function planta()
{
return $this->belongsTo('App\Plantas', 'planta_id', 'ID');
}
}
To catch the name of planta
:
{{ Auth::user()->planta()->Nome }}
Observing: put the name of the fields in lowercase and if it is composed separately by underscore
, standard nomenclature for development. Nothing prevents it from being otherwise, but it is more readable when it comes to Larable with Laravel-eloquent
I did not notice the names of the fields, because the part of the model User
!
Link: One To Many
you have the models of these two tables and relations ready? if you have the model you can ask the question?
– novic
I do have to put
– will