There is a lot special functions that helps simplified our code like this
find($id)
takes an id and returns a single model. If no matching model exist, it returnsnull
.findOrFail($id)
takes an id and returns a single model. If no matching model exist, it throws an error.first()
returns the first record found in the database. If no matching model exist, it returnsnull
.firstOrFail()
returns the first record found in the database. If no matching model exist, it throws an error.get()
returns a collection of models matching the query.lists($column)
returns a collection of just the values in the given column.toArray()
converts the model/collection into a simple PHP array.
Looking for more? Visit here or https://laravel.com/docs/5.3/eloquent-collections.
Leave a Reply