Skip to content

Laravel Special Method

There is a lot special functions that helps simplified our code like this

  1. find($id) takes an id and returns a single model. If no matching model exist, it returns null.
  2. findOrFail($id) takes an id and returns a single model. If no matching model exist, it throws an error.
  3. first() returns the first record found in the database. If no matching model exist, it returns null.
  4. firstOrFail() returns the first record found in the database. If no matching model exist, it throws an error.
  5. get() returns a collection of models matching the query.
  6. lists($column) returns a collection of just the values in the given column.
  7. toArray() converts the model/collection into a simple PHP array.

Looking for more? Visit here or https://laravel.com/docs/5.3/eloquent-collections.

 

Published inICT

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

{"value":"\n