I'm getting the following error when clicking on permissions, button that directs to this controller:
Error:
Undefined property: App \ Http \ Controllers \ RolesController :: $ role
Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Role;
class RolesController extends Controller
{
//Exibe Lista de Roles
public function ListRoles(role $role)
{
$roles = $role->all();
return view('Roles/roles', compact('roles'));
}
//Exibe Formulário de edição
public function edit($idRole)
{
$role = role::find($idRole);
if(empty($role)){
return view('alert');
}
return view('Roles/roles-update', compact('role'));
}
//Salva alterações do formulário de edição
public function save($idRole)
{
$name = Request()->input('name');
$label = Request()->input('label');
$role = role::find($idRole);
$role->name = $name;
$role->label = $label;
$role->save();
return redirect()->action('RolesController@ListRoles')->withInput();
}
//Deletar uma Role
public function delete($idRole)
{
$role = role::find($idRole);
$role->delete();
return redirect()->action('RolesController@ListRoles');
}
//enviar permissao da role para a view de permissao da role
public function permissions($id)
{
$role = $this->role->find($id);
$permissions = $role->permissions;
return view('roles/permissions', compact('role', 'permissions'));
}
}
RESOLVED:
public function permissions($idRole)
{
$role = role::find($idRole);
$permissions = $role->permissions;
return view('roles/permissions', compact('role', 'permissions'));
}