Question: Well i am using laratrust to handle roles and permissions for my application. 

I want to attach a role to a user when registering but after reading laratrust documentation i cant seem to figure out whats the issue!

Here is my code 

```
 public function register(Request $request) { 
     $this->validation($request); 
     User::create([ 
               'name' => $request->name,
                'lastname' => $request->lastname, 
                'email' => $request->email, 
                'password' => bcrypt($request->password)
     ]);

      $user->attachRole($employer);

      Auth::attempt([
               'email' =>$request->email, 
               'password' => $request->password]);
             // Authentication passed...
      return redirect('/'); 
  }

```

With the above i get error unknown query builder attacheRole!

Any suggestions?

Answer: 
you forget to define **$user** (see in my code example) but there would be also error with the **$employer** it isn't definied in the function...

```
$user = User::create([ 
      'name' => $request->name,
     'lastname' => $request->lastname, 
     'email' => $request->email, 
     'password' => bcrypt($request->password)
 ]);
 $user->attachRole($employer);

```

[Laratrust Examples & doc](https://github.com/santigarcor/laratrust/blob/5.0/docs/usage/concepts.rst)
This works for me

```
User::create([ 
               'name' => $request->name,
                'lastname' => $request->lastname, 
                'email' => $request->email, 
                'password' => bcrypt($request->password)
     ])->attachRole('employer');

```