Using DATETIME Fields Instead of Booleans class Post extends Model { public function isPublished(): bool { return $this->published_at !== null; // is_published }} Using 'when' in PendingRequest $http = Http::withBasicAuth($username, $password); if (app()->environment('local')) { $http->withoutVerifying(); } // with when $http = Http::withBasicAuth($username, $password) ->when(app()->environment('local'), function (PendingRequest $request) { $request->withoutVerifying(); }); Using getOrPut() in Collections if (!

Our code might look like so if ($user->approved === Approval::APPROVED) { // Do something... } our model might now look like this class User extends Model { public function isApproved(): bool { return $this->approved === Approval::APPROVED; }} // now if ($user->isApproved()) { // Do something... } Changing the Key for Route Model Binding let's say that you have a route that accepts a blog post's slug Route::get('blog/{slug}', [BlogController::class, 'show']); // Model use App\Actions\PublishPost; use App\Models\Post; class BlogController extends Controller { public function show($slug) { $post = Post::where('slug', $slug)->firstOrFail(); return view('blog.show', [ 'post' => $post, ]); }} to simplify this code and clean it up, we could update the slug parameter to be post:slug instead
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners