app/Role.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model as EloquentModel;
/**
* @property \Illuminate\Support\Collection $permissions
*/
class Role extends EloquentModel
{
/**
* A role may be given various permissions.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function permissions()
{
return $this->belongsToMany(Permission::class);
}
/**
* Grant the given permission to a role.
*
* @param \App\Permission $permission
*
* @return mixed
*/
public function givePermissionTo(Permission $permission)
{
return $this->permissions()->save($permission);
}
}