2
Hi, I happen to be taking my first steps on the Laravel. I created a database with two tables (dependents and employees), created the crud of each and display the whole system in html (bootstrap). The problem is that I am not able to create a page where, when clicked on the employee button, goes to the list of dependents of this user. The ratio is 1 to N.
Using Tinker I can list, but I would like to display it in the system, in html (as I do with the general list of dependents and employees). I found this in the documentation but did not get many results in the project: https://laravel.com/docs/5.3/eloquent-relationships#querying-Relations
namespace App;
use Illuminate\Database\Eloquent\Model;
class Funcionario extends Model {
protected $fillable= [
'codigo',
'nome',
'sexo'
];
public function todosDependentes(){
return $this->hasMany('App\Dependente', 'funcionario_id', 'id');
}
}
namespace App;
use Illuminate\Database\Eloquent\Model;
class Dependente extends Model{
protected $fillable = [
'funcionario_id',
'nome',
'dataNascimento'
];
public function funcionario(){
return $this->belongsTo('App\Funcionario', 'id', 'funcionario_id');
}
}
Put both
Models
in your question!!!– novic
edited the post
– RamonVicente
The answer made clarifies you, yes no and why?
– novic
Yes, thank you very much!
– RamonVicente