You see, I have a table User:
Schema::create('users', function(Blueprint $table){
$table->increments('id');
$table->string('name');
$table->string('second_name')->nullable();
$table->string('provincia')->nullable();
$table->string('localidad')->nullable();
$table->string('direccion')->nullable();
$table->string('telefono');
$table->string('email')->unique();
$table->string('password');
$table->string('dni');
$table->boolean('vehiculo')->default(false);
$table->string('foto')->nullable();
$table->rememberToken();
$table->timestamps();
});
I want to make a view that allows to see all the users. For this I have this link in web.php:
Route::get('/inicio', 'UserController@index');
I have this code in UserController.php:
public function index(){
$usuarios=User::latest()->paginate(5);
return view('menus.inicio',compact($usuarios));
}
And I have the following view:
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h1 class="text-center text-mute"> Usuarios </h1>
@forelse($usuarios as $u)
<div class="panel panel-default">
<div class="panel-heading">
<h2> {{ $u->name }} </h2>
</div>
<div class="panel-body">
<h4>{{ $u->dni }}</h4>
<h4>{{ $u->telefono }}</h4>
</div>
</div>
@empty
<div class="alert alert-danger">
<h1>No hay ningún usuario por el momento</h1>
</div>
@endforelse
</div>
</div>
@endsection
But I get the following error:
If I use dd ($ users) it works, so I would like to know what I do wrong in the view.