Skip to content

Instantly share code, notes, and snippets.

@wichaksono
Created March 15, 2018 00:54
Show Gist options
  • Save wichaksono/23024ea5056e3d3509e5874f2341f36b to your computer and use it in GitHub Desktop.
Save wichaksono/23024ea5056e3d3509e5874f2341f36b to your computer and use it in GitHub Desktop.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class UserRole extends Model
{
protected $primaryKey = 'user_id';
protected $table = 'role_user;
public $timestamps = false;
protected $fillable = [
'user_id', 'role_id'
];
/*
* Method untuk yang mendefinisikan relasi antara model user dan model userRole
*/
public function users()
{
return $this->belongsToMany(User::class);
}
/*
* Method untuk mengambil object dari user
*/
public function getUserObject()
{
return $this->belongsTo(User::class);
}
/*
* Method untuk mengambil object dari role
*/
public function getRoleObject()
{
return $this->belongsTo(Role::class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment