My Blog Posts

Use of Solid Design Principle with Laravel 1

Use of Solid Design Principle with Laravel 1


What is SOLID?

SOLID stands for ** of the first five object-oriented design (OOD) ** principles known to Robert C. Martin as [Uncle Bob ( https://en.wikipedia.org/wiki/Robert_Cecil_Martin ).

Solid Means?

Q — Single responsibility policy
O — On-off policy
L — Liskov ia0 principle
I — Interface allocation policy
D — Policy for reducing dependency

Purpose of SOLID Design Principles:

  1. To make the code more sustainable.
  2. Make it easier to read and understand code.
  3. Make it easy to quickly expand the system with new functionality without disrupting existing functions.
  4. Write clean code.

Q — Let's Look at the Single Responsibility Policy.

According to the official definition of the single responsibility principle

There must be only one reason for a class to change.

What does that mean? Let's understand with an example in Laravel. Controller
Storemethod (in question) Storemethod of use PostController) and Store The validate operation will look like this.

Where we apply the Single responsibility policy, Laravel removes the Form Request object from the package. Create a form request using an artisan command.

php artisan make:request StoreBlogPost

Creates the new request class app\Http\Request\StoreBlogPost.

Now click the form request that we created PostControllerlet's also change it to use StoreBlogPost.

Automatically vensies the Form Request and returns verified requests. You can now use this method to vent your data as you like.

In this article, we learned how to make the first letter of solid concept, S, i.e. the only principle of responsibility. I hope this spelling has been useful.



Share this article


Comments (0)

Comment