Undefined variable: users

2
  

Undefined variable: users (View: C: \ Users \ Vitoria \ Desktop \ Laravel \ resources \

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');
}
    
asked by anonymous 27.03.2017 / 16:05

1 answer

3

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

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

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

return view('painel', ['meuNomeDaVariavel' => 'valorDaVariavel']);
    
27.03.2017 / 16:08