title: Laravel - Filter a collection by a dynamic field
body: <p>The model has 3 fields that are attributes of the model and the 4th field is a dynamic field that is called "fullTitle"</p>
  
  <pre><code>[
      {
      "id": 1,
      "hours": 2000,
      "car_id": 3,
      "fullTitle": "Test",
      }
  }
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App;
  
  use App\Car;
  
  
  
  class VenderModel extends Model
  {
      use TranslationTrait;
  
      protected $guarded = ['*'];
  
      /**
       * The accessors to append to the model's array form.
       *
       * @var array
       */
      protected $appends = [
          'fullTitle'
      ];
  
  
      /**
       * Accessor for dynamic property fullTitle to use as selector name.
       * @param string $locale
       * @return null|string|string[]
       */
      public function getFullTitleAttribute($locale = 'es')
      {
          if (null === $this-&gt;hasTranslation()) {
              return trans('errors.No name');
          }
  
          return preg_replace('/\s{2,}/', ' ', $this-&gt;code.' '. $this-&gt;translationOrFirst($locale)-&gt;translation);
      }
  
  }
  
  
  
      public function index(Request $request): JsonResponse
      {
          $limit      = $request-&gt;input('limit', 25);
          $title      = $request-&gt;input('title');
  
          $query = VenderModel::all();
  
          $query-&gt;when($request-&gt;query('title'), function ($q) use ($title) {
              return $q-&gt;where('fullTitle', 'like', '%' . $title . '%');
          });
  
          return response()-&gt;json($query, 200);
  
      }
  </code></pre>
  
  <p>What I'm trying to do is pick up the elements with the fullTitle but doesnt work</p>