It’s amazing how life gets going in a rhythm, and you get your head down and working so hard, that you sometimes forget to look around (or in this case, write in your blog). Working at a small travel advertising
Defensive Programming | Laravel find()
Defensive Programming One of the things I’ve learned in my career is to code defensively. Laravel makes it very easy to ask for an object, but it also makes it very easy to get it wrong. If you request an
Laravel – the difference between all() and get()
When dealing with a model, all() is a static method. It creates a new query object, and runs get() on that object get() is not static, but can be called statically because of a magic method in the Model class.
Laravel Eloquent only()
$fullModel = Model::find(1) // Get model with id 1 $idArray = $fullModel->only(‘id’) // array containing id // this does not work. You’ll get back an empty collection // It is trying to pull the id column off the collection object,
Laravel Eloquent Attributes
When dealing with an Eloquent model, you can add your own attributes. These can be useful for computed values. For example: class Person extends Model { // By default, all the database fields will be available. // Let’s assume for