Skip to main content

Posts

Showing posts with the label Clean Code

20 Laravel Tips Every Developer Should Know (But Commonly Overlooked)

20 Laravel Tips Every Developer Should Know (But Commonly Overlooked) Laravel is powerful, elegant, and developer-friendly—but many of its gems remain hidden or underused. Here are 20 Laravel tips and features that you might not be using yet but definitely should. 1. Eloquent Accessors & Mutators Format your model's attributes when retrieving ( Accessor ) or setting ( Mutator ) them. public function getNameAttribute($value) { return ucfirst($value); } 2. Route Model Binding Let Laravel automatically inject models into routes, making code cleaner and error-free. Route::get('/user/{user}', function(User $user) { return $user; }); 3. $fillable and $guarded Control which fields can be mass assigned to prevent mass assignment vulnerabilities. 4. Query Builder’s when() Method Build clean conditional queries without unnecessary if-else blocks. 5. Blade Directives: @isset, @empty, @auth Make your B...

How to Write DRY Code in Node.js Using Helper Functions – Beginner’s Guide

How to Write DRY Code in Node.js Using Helpers As developers, one of the most important principles we should follow is DRY: Don't Repeat Yourself . Repetition makes code harder to maintain and debug. In this post, you'll learn how to write cleaner, reusable, and DRY code in Node.js using helper functions. 💡 What is DRY Code? DRY code means reducing repetition in your codebase. Instead of copying and pasting the same logic multiple times, you extract that logic into a function (or helper), then reuse it wherever needed. 🛠️ What are Helpers in Node.js? Helpers are utility functions that handle repetitive tasks like formatting, validation, date conversions, logging, etc. These are usually stored in a separate file (like helpers.js ) to keep the main code clean. 📁 Example Project Structure project/ ├── helpers/ │ └── stringHelper.js ├── routes/ │ └── userRoutes.js ├── app.js ✍️ Example: Creating a Helper ...