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 ).
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:
- To make the code more sustainable.
- Make it easier to read and understand code.
- Make it easy to quickly expand the system with new functionality without disrupting existing functions.
- 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
Store The validate operation will look like this.
namespace App\Http\Controllers use App\Http\Controllers\Controller;class PostController extends Controller $validator = Validator::make($request->all(), [
public function store(Request $request)
'title' => 'required|string|max:200',
'description' => 'required|string',
use App\Post; // validate incoming request // finally store our post
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
Now click the form request that we created
PostControllerlet's also change it to use
namespace App\Http\Controllers use App\Http\Controllers\Controller;class PostController extends Controller
public function store(StoreBlogPost $request)
use App\Post; // finally store our post
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.