-
Notifications
You must be signed in to change notification settings - Fork 0
05 Modeli
Ivan Radunovic edited this page May 9, 2017
·
1 revision
Sve modele čuvamo u novom direktorijumu app/Models
, potrebno je premjestiti Users.php
tamo i izmijeniti mu namespace.
Model Role
komunicira sa tabelom roles
i izgleda jednostavno:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
}
Ovaj model ima relaciju sa modelom Role
. Jedan korisnik ima jednu "rolu" ili tip, a svaki tip može da ima više korisnika.
Dodamo sledeće u User.php
:
public function role()
{
return $this->belongsTo('App\Models\Role');
}
Možemo dodati u metodu za provjeru da li je korisnik određenog tipa:
public function hasRole($name)
{
return $this->role->name == $name;
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Event extends Model
{
}
Codingo D.O.O. Podgorica 2017.