Created
March 15, 2018 00:54
-
-
Save wichaksono/23024ea5056e3d3509e5874f2341f36b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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