Skip to content

Instantly share code, notes, and snippets.

@ambrosiora
Created February 5, 2020 19:11
Show Gist options
  • Save ambrosiora/e65169f5dba94b2822ed3bcedaeb8e46 to your computer and use it in GitHub Desktop.
Save ambrosiora/e65169f5dba94b2822ed3bcedaeb8e46 to your computer and use it in GitHub Desktop.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class PapelUsuario extends Model
{
protected $table = 'papel_usuarios';
public function users()
{
return $this->belongsToMany('App\User', 'user_sistema_papel_usuarios')->withPivot('sistema_id');//->as('user_sistema_papel_usuarios');
}
public function sistemas()
{
return $this->belongsToMany('App\Sistemas', 'user_sistema_papel_usuarios')->withPivot('user_id');//->as('user_sistema_papel_usuarios');
}
// public function newPivot(Model $parent, array $attributes, $table, $exists, $using = NULL)
// {
// if ($parent instanceof Sistema) {
// return new SistemaGroupPivot($attributes, $table, $exists);
// }
// if ($parent instanceof User) {
// return new UserGroupPivot($attributes, $table, $exists);
// }
// return parent::newPivot($parent, $attributes, $table, $exists);
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment