title: Spatie laravel-permissions Giving Error of Argument 1 Passed
body: <p>I'm working with the Spatie laravel-permissions package. When I create my role I want to assign permissions to roles but it's returning the error:</p>
  
  <blockquote>
    <p>Argument 1 passed to
    Spatie\Permission\Exceptions\GuardDoesNotMatch::create() must be of
    the type string, null given, called in
    C:\xampp\htdocs\blog\vendor\spatie\laravel-permission\src\Traits\HasPermissions.php
    on line 505</p>
  </blockquote>
  
  <p><strong>Controller</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>public function store(Request $request)
  {
      // Validate name and permissions field
      $this-&gt;validate($request, [
              'name' =&gt; 'required|unique:' . config('permission.table_names.roles') . '|max:10',
          ]
      );
  
      $name = $request['name'];
      $role = new Role();
      $role-&gt;name = $name;
  
      $permissions = $request-&gt;permissions;
      $role-&gt;save();
  
      // Looping thru selected permissions
      foreach ($permissions as $permission) {
          $p = Permission::where('id', '=', $permission)-&gt;firstOrFail();
          // Fetch the newly created role and assign permission
          $role = Role::where('name', '=', $name)-&gt;first();
          $role-&gt;givePermissionTo($p);
      }
  
      return redirect()-&gt;route('roles.index')
          -&gt;with('flash_message',  'Role' . $role-&gt;name . ' added!');
  }
  </code></pre>
  
  <p><strong>Blade</strong></p>
  
  <pre><code>&lt;div class='col-lg-10 col-lg-offset-4'&gt;
      &lt;h1&gt;&lt;i class='fa fa-key'&gt;&lt;/i&gt; Add Role&lt;/h1&gt;
      &lt;hr&gt;
      &lt;form action="{{action('RoleController@store')}}" method="post" enctype="multipart/form-data"&gt;
          {{ csrf_field() }}
          &lt;div class="form-group row" style="margin:5%;"&gt;
              &lt;label for="name" class="col-sm-2 col-form-label"&gt;Name *&lt;/label&gt;
              &lt;input type="text" class="form-control col-sm-10" id="name" name="name"
                     placeholder="Enter your Role Name"/&gt;
          &lt;/div&gt;
  
          &lt;h5&gt;&lt;b&gt;Assign Permissions&lt;/b&gt;&lt;/h5&gt;
          &lt;div class="form-check"&gt;
              @foreach ($permissions as $permission)
                  &lt;input class="form-check-input" type="checkbox" name="permissions[]" value="{{ $permission-&gt;id }}"&gt;
                  &lt;label class="form-check-label" for="defaultCheck1"&gt;
                      {{$permission-&gt;name}}
                  &lt;/label&gt;
              @endforeach
          &lt;/div&gt;
          &lt;div class="form-group row" style="margin:5%;"&gt;
              &lt;button type="submit" class="btn btn-primary col-sm-3 col-sm-offset-3"&gt;Add Role&lt;/button&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Can someone help me solve this problem?</p>
  
  <p>This is the screenshot
  <a href="https://i.stack.imgur.com/egK7o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/egK7o.png" alt="dd($request-&gt;permissions);"></a></p>