There are two templates in the first one, everything is displayed normally. The second error is:
Trying to get property 'name' of non-object
With what it can be connected ?
The first controller UserController.php
public function index() { return view('user_managment.user.index',[ 'users' => User::paginate(10) ]); }
first template index.blade.php
{{$user->roles->name}}
second controller RoleController.php
public function create() { return view('role_managment.role.create',[ 'role' => '', 'users' => User::all() ]); }
second template create.blade.php
@foreach ($users as $user) {{$user->name}} {{$user->roles->name}} {{-- @isset($user->roles->name) пользователя уже имеет роль @endisset --}} </label> <br> @endforeach
Role model
public function roles() { return $this->belongsTo('App\Specialty','role','id'); }
User Model
public function user() { return $this->hasMany('App\User','role','id'); }