<?php namespace App\Models;

use DB;
use Spatie\Permission\Traits\HasRoles;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

class Permission2 extends Permission
{

     public function getCreatedAtAttribute()
    {
        return ($this->attributes['created_at']!=null)?date('d/m/Y h:i:s', strtotime($this->attributes['created_at'])):"";
    }



	public function getroles()
	{
	    $liste_roles="";
		$permission_roles =  DB::table('role_has_permissions')->where('permission_id', '=', $this->id)->get();

		foreach ($permission_roles as $permission_role)
		{
			$role=Role::find($permission_role->role_id);
		    $liste_roles .=(($liste_roles=="")?"":"<br/>").($role->name);
		} 
	    return $liste_roles;
	 }

	public function getGroupeNomAttribute()
	{
	    
		$groupe =  PermissionGroupe::find($this->id_groupe);
		if(!$groupe) return "";
	    return $groupe->nom;
	 }

}