title: `Undefined variable: roles` in Laravel blade template
body: <p>I'm creating a file called <code>edit.blade</code> to edit users.</p>
  
  <p>The problem is, when i'm trying to make a list with all roles, Laravel prints the following error:</p>
  
  <pre><code>Undefined variable: roles (View: /home/ubuntu/workspace/resources/views/user/edit.blade.php)
  </code></pre>
  
  <p>Here is my <code>edit.blade</code> template:</p>
  
  <pre><code>@extends ('adminlte::page')
  @section('content')
   &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css"&gt;
  
  &lt;div class="container" style="margin-left:25%"&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-md-8 col-md-offset-2"&gt;
              &lt;div class="panel panel-default"&gt;
                  &lt;div class="panel-heading"&gt;
                      &lt;h2&gt;Editar datos del Usuario&lt;/h2&gt;
                  &lt;/div&gt;
  
                  &lt;div class="panel-body"&gt;
                      &lt;form class="form-horizontal" method="POST" action="{{ route('user.update', ['user' =&gt; $user-&gt;id]) }}"&gt;
                          {{ csrf_field() }}
                          &lt;input type="hidden" name="_method" value="PUT"/&gt;
  
  
  
                          &lt;div class="form-group{{ $errors-&gt;has('name') ? ' has-error' : '' }}"&gt;
                              &lt;label for="name" class="col-md-4 control-label"&gt;
                                  Nombre
                              &lt;/label&gt;
  
                              &lt;div class="col-md-6"&gt;
                                  &lt;input id="name" type="text" class="form-control" name="name" value="{{ $user-&gt;name }}"  autofocus style=" "&gt;
  
                                  @if ($errors-&gt;has('name'))
                                      &lt;span class="help-block"&gt;
                                          &lt;strong style=" "&gt;{{ $errors-&gt;first('name') }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                  @endif
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group{{ $errors-&gt;has('email') ? ' has-error' : '' }}"&gt;
                              &lt;label for="email" class="col-md-4 control-label"&gt;
                                  Email
                              &lt;/label&gt;
  
                              &lt;div class="col-md-6"&gt;
                                  &lt;input id="email" type="text" class="form-control" name="email" value="{{ $user-&gt;email }}"  autofocus style=" "&gt;
  
                                  @if ($errors-&gt;has('email'))
                                      &lt;span class="help-block"&gt;
                                          &lt;strong style=" "&gt;{{ $errors-&gt;first('email') }}&lt;/strong&gt;
                                      &lt;/span&gt;
                                  @endif
                              &lt;/div&gt;
                          &lt;/div&gt; 
  
  
                              &lt;div class="form-group"&gt;
  
                                   &lt;label for="club" class="col-md-4 control-label"&gt;
                                  Club
                                  &lt;/label&gt;
                                  &lt;div class="col-md-6"&gt;
                                  &lt;select name="id_club" &gt;
                                  @foreach($clubs as $club)
  
                                      &lt;option value="{{$club-&gt;id_club}}" class="form-control"&gt;{{$club-&gt;nombre}}&lt;/option&gt;
  
                                      @endforeach
                                  &lt;/select&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                              &lt;div class="form-group"&gt;
  
                                   &lt;label for="roles" class="col-md-4 control-label"&gt;
                                  Rol
                                  &lt;/label&gt;
                                  &lt;div class="col-md-6"&gt;
                                  &lt;select name="role_id" &gt;
                                  @foreach($roles as $role)
  
                                      &lt;option value="{{$role-&gt;id}}" class="form-control"&gt;{{$role-&gt;name}}&lt;/option&gt;
  
                                      @endforeach
                                  &lt;/select&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;div class="modal-footer"&gt;
                              &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
                              &lt;button type="submit" class="btn btn-primary"&gt;Guardar&lt;/button&gt;
                            &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  @endsection
  
  </code></pre>
  
  <p>And my this is my <code>UserController</code> that calls the blade template with the relevant variables:</p>
  
  <pre><code>    public function edit(User $user)
      {
          $roles = Role::all();
          $clubs = Club::all();
          return view('user.edit', ['user' =&gt; $user], ['clubs' =&gt; $clubs], ['roles' =&gt; $roles]);
      }
  
      /**
       * Update the specified resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \App\User  $user
       * @return \Illuminate\Http\Response
       */
      public function update(Request $request, User $user)
      {
          $user-&gt;save();
          $user-&gt;roles()-&gt;sync([$request-&gt;input('role_id')]);
          //$user-&gt;update($request-&gt;all());
          return redirect()-&gt;route('user.index');
      }
  </code></pre>
  
  <p>I'm including <code>use App\Role;</code> at the top of this file.</p>