title: Laravel pluck with custom method from model
body: <p>I'm using Laravel <code>5.6</code>. I have a <code>users</code> table and <code>firstname</code> and <code>lastname</code> fields.</p>
  
  <p>In my <code>User</code> model I also have this function</p>
  
  <pre><code>public function name()
  {
      return $this-&gt;firstname . ' ' . $this-&gt;lastname;
  }
  </code></pre>
  
  <p>And now in another controller, I want to create a dropdown menu with all the users. But I would like to display the <code>name()</code> and not only the first/lastname.</p>
  
  <p>I'm currently using this</p>
  
  <pre><code>$users = \App\User::pluck('lastname', 'id');
  return view('myview', compact('MY_collection' , 'users'));
  </code></pre>
  
  <p>And in my view (with <a href="https://laravelcollective.com/docs/5.4/html" rel="noreferrer">collective/html</a>)</p>
  
  <pre><code>{!! Form::select('user', $users, isset($user) ? $MY_collection-&gt;user: null,  ['class' =&gt; 'form-control']) !!}        
  </code></pre>
  
  <p>Is is possible to use pluck with a method function ? Or should I do something else?</p>
  
  <p>I am also aware of the <a href="https://laravel.com/docs/5.6/eloquent-mutators#defining-an-accessor" rel="noreferrer">accessor</a> solution but I don't have a <code>name</code> attribute in the database, so it is not working.</p>