Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Funcao extends Model
- {
- protected $table = 'funcao';
- protected $primaryKey = 'id';
- protected $fillable = ['id','url','nome'];
- public $timestamps = false;
- public function areas()
- {
- return $this->belongsToMany(area_atuacao::class,'fun_area','fun_id','area_id')
- ->as('fun_area')
- ->withPivot(['mostrarMenu']);
- }
- }
- class area_atuacao extends Model
- {
- //
- protected $primaryKey = 'id';
- public $timestamps = false;
- protected $fillable = ['id','nome','ativo'];
- public function funcaos()
- {
- return $this->belongsToMany(Funcao::class,'fun_area','area_id','fun_id')
- ->as('fun_area')
- ->withPivot(['mostrarMenu']);
- }
- }
- //controller
- public function store(Request $request)
- {
- //
- if(!empty($request['permissoes']))
- {
- $funcao = null;
- foreach ($request['permissoes'] as $permissoe)
- {
- $idFuncao = (integer)$permissoe["funcao"];
- $funcao = new Funcao();
- $funcao = $funcao->find($idFuncao);
- $funcao->areas()->sync(['area_id'=>$permissoe['area'],'mostrarMenu'=>false]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement