0
I have an entity that is employees and other 3 tables that are Sector, Office and Department and the relationship is 1 for N (i.e., the primary keys of these 3 tables must become foreign in the official table).
In my View
in the employee register has a select
for each of those entities (Office, Sector and Dpt) that must be populated with the records already registered in the bank.
But I couldn’t make the relationship and I don’t know what I could call the method
in View
. Gives way that I made here he appeared the id of the position and not the name of the position and when I erased the record of View
left the select, ie I’m doing wrong pulling the View
and not from the bank as it should be. Could you help me?
I will post the Employee and Position Model and also the part of View
where "fill" the select
EMPLOYEE MODEL
<?php
namespace App\Models\Treinamento;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Funcionario extends Model
{
protected $fillable = [
'nome_funcionario', 'email_funcionario', 'instrutor',
];
protected $guarded = [
'id', 'cargos_id', 'setors_id', 'departamentos_id'
];
protected $table = 'funcionarios';
use SoftDeletes;
protected $dates = ['deleted_at'];
}
ROLE MODEL
<?php
namespace App\Models\Treinamento;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Cargo extends Model
{
protected $fillable = [
'nome_cargo'
];
protected $table = 'cargos';
use SoftDeletes;
protected $dates = ['deleted_at'];
}
PART OF THE VIEW (SELECT POSITION)
div class="row">
<div class="col-md-4">
<strong>Selecione o Cargo</strong>
<select name="cargos_id" class="form-control" required="ON">
<option value="">Clique aqui</option>
@foreach ($classcargo_array as $cargos_id)
<option value="{{$cargos_id->id}}" > {{$cargos_id->nome_cargo}}
</option>
@endforeach
</select>
</div>
Possible duplicate of How to use hasmany relationship in Laravel 5.2?
– novic