Error Undefined property

1

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'));
    }
    
asked by anonymous 26.04.2018 / 21:33

1 answer

1

The property roles to $this does not really exist. At the beginning of your class, declare:

private $role;

It will exist, thus avoiding the current error on line 61, but when you call $this->roles this will probably return null , so you must create a Construct or PreDispatch, it depends on your Framework to define what your roles will be .

    
26.04.2018 / 21:51