return view('admin.role', array ( 'roles' => $roles ));
May 12, 2017
11
Level 1
Cannot use object of type stdClass as array
I have a function in my controller. Here are three ways to get all data from database table. All work fine but I can pass to View only first. Other two which are commented cause error Cannot use object of type stdClass as array (View: /var/www/doctor_lar/resources/views/admin/role.blade.php)
public function roles_list(){
$roles = Role::all();
//$roles = DB::select('SELECT * FROM roles');
//$roles = DB::table('roles')->get();
return view('admin.role')->with(['roles'=>$roles]);;
}
Level 122
the answer depends on which Laravel version you are using
The difference is the return type of eloquent and DB are not the same
In your view, are you accessing the roles like $role['name']?
Please or to participate in this conversation.