Undefined variable: users

Asked

Viewed 1,036 times

1

Undefined variable: users (View: C: Users Vitoria Desktop Laravel Resources views painel.blade.php)

Panel.blade.php

<!DOCTYPE html>
<html lang="pt-br">
   <head>
       <meta charset="utf-8"/>
       <title>BEM VINDO ADMNISTRADOR</title>
   </head>

<body>


    <form method="POST" action="painel">

    @foreach ($users as $user)
        <h1> BEM VINDO ADMINISTRADOR!</h1>

        <p>Nome: {{$user->Name}}</p> <br>
        <p>E-mail: {{$user->User}}</p><br>
        <p>Tipo: {{$user->Tipo}}</p> <br>
        <p>Estado: {{$user->Ativo}}</p>     

    @endforeach

    </form>
</body>
</html>

Clientscontroller

public function painel()
{
    $user = \App\User::all();
    return View('/painel');
}

1 answer

3


You need to pass the variable $user through function view()

$user = \App\User::all();
return view('painel', ['users' => $user]);

The second parameter of view() is a array with the index being the name of the variable that will be used in the view, so if you want to use another variable name in the view do:

return view('painel', ['meuNomeDaVariavel' => 'valorDaVariavel']);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.