Search code examples
databaselaravelsearchcollectionseloquent

Laravel Eloquent Collection Search always returns false


When I use the Laravel Collection search function it always returns false.

Code :

$entries = Entry::all();
$results = $entries->search('Jack', true);
dd($results);

Output :false

Output dd($entries) :

    Collection {#218 ▼
  #items: array:9 [▼
    0 => Entry {#219 ▼
      #fillable: array:2 [▶]
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:5 [▶]
      #original: array:5 [▶]
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #events: []
      #observables: []
      #relations: []
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #guarded: array:1 [▶]
    }
    1 => Entry {#220 ▶}
    2 => Entry {#221 ▶}
    3 => Entry {#222 ▶}
    4 => Entry {#223 ▶}
    5 => Entry {#224 ▶}
    6 => Entry {#225 ▶}
    7 => Entry {#226 ▶}
    8 => Entry {#227 ▶}
  ]
}

Sorry for the horrible formatting.


Solution

  • I added the Eloquence[0] package.

    [0] = https://github.com/jarektkaczyk/eloquence