I have an entity that is employees and 3 other tables that are Sector , Position and Department and the relationship is 1 for N (that is, the primary keys of these 3 tables must be foreign in the employee table).
In my View
in the employee's registry has a select
for each of these entities ( Position , Sector and Dpt ) which must be populated with the records already registered in the bank.
But I could not make the relation and I do not know how I could call the method
in View
. So I did it here it appeared the job id and not the job name and when I deleted the registry of View
it left the select, ie I'm doing wrong by pulling View
and not the bank as it should be. can you help me?
I will post the Employee and Charge Model and also the share of View
where "fill in" 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'];
}
POST 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 (POST SELECT)
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>