πŸ˜—KISS

Keep It Simple, Stupid. Even if the solution looks stupid, a simple one is better than a complex one. This principle encourages writing clean, simple, and maintainable code. Instead of overcomplicating logic, you should break down tasks into smaller, reusable, and structured components.

Routing (Follow RESTful Conventions)

Use resourceful routes instead of defining each route manually.

❌ Bad Example (Manually Defining Routes)

Route::get('/users/all', 'UserController@getAll');
Route::post('/users/create', 'UserController@store');
Route::put('/users/update/{id}', 'UserController@update');
Route::delete('/users/delete/{id}', 'UserController@destroy');

βœ… Good Example (KISS Applied)

Route::resource('users', UserController::class);

βœ” Why?

  • Uses Laravel’s built-in RESTful methods.

  • Reduces redundancy and improves maintainability.


Controllers (Short & Focused Methods)

Keep controllers clean by separating validation and business logic.

❌ Bad Example (Controller Doing Too Much)

βœ… Good Example (KISS Applied)

βœ” Why?

  • Uses UserRequest for validation.

  • Uses UserService For business logic, keep the controller clean.

UserRequest (Separate Validation)


Models & Eloquent Queries (Use Scopes & Relationships)

❌ Bad Example (Raw Query & Complex Logic)

βœ… Good Example (KISS Applied)

βœ” Why?

  • Uses Eloquent scopes (active()).

  • Uses latest() instead of manual sorting.

User Model: Adding Scope

βœ” Now, you can call:

πŸš€ More readable, reusable, and maintainable!


Service Classes (Encapsulate Business Logic)

A service class helps keep controllers lean by handling business logic separately.

Example: UserService for Business Logic

βœ” Now, the controller only delegates work to UserService.


Blade Templates (Avoid Logic in Views)

❌ Bad Example (Logic Inside Blade)

βœ… Good Example (KISS Applied)

βœ” Why?

  • Moves logic to the model, making the Blade file cleaner.

  • Improves reusability across the application.

Last updated