Skip to content

Mastering PHP and Laravel

Never stop learning!

Menu

  • Home
  • Blog Posts
  • Humor

Eloquent

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

Kenny February 5, 2019September 27, 2023 Blog Posts, Eloquent, Laravel, PHP Read more

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.

Kenny October 12, 2018September 27, 2023 Blog Posts, Eloquent, Laravel, Learning, Programming Read more

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,

Kenny October 12, 2018September 27, 2023 Blog Posts, Eloquent, Laravel, Learning, Programming Read more

Archives

Categories

Copyright © 2025 Mastering PHP and Laravel. All rights reserved. Theme Spacious by ThemeGrill. Powered by: WordPress.