Is my use of Laravel Repository-Service pattern correct?
Hello everyone,
I'm new and I've been working on patterns for about 2 weeks and I've been implementing my applications. But I'm not sure about their accuracy, so I wanted the professionals here to see and comment. Please inform me if I'm wrong or help me optimize them. Because I will use it everywhere in my project and I need it very much. Thank you very much in advance.
@Snapey I get it, this might be the best news I've ever gotten because I've been trying to figure this out for days and as you say it's really complicated. So what would you suggest to me, by the way, thank you for the information.
The only thing I want is not to repeat code by typing the same update and store commands for everything (user, post, category, etc.).
public function store (UserRequest $request, User $user)
{
$user->fill($request->validated());
$user->save();
return redirect('users.index')->with('success','User data saved');
}
Then think how this would be with repository pattern and service class, and how much code is duplicated.
@Snapey It looks very good and the workload is light, but I have heard that batch assignments are harmful. when I fill or save, I have to write all the data in the fillable one by one. Does this cause a security weakness?
@Snapey In other words, even if we write everything in fillable, the names we write in the request class are processed and attackers cannot reach the places where we write outside the request. This information is really gold for me, thank you very much. I got rid of tens of lines of code
@beyondelayer I don't want to stop you learning about design patterns, just highlighting that repository pattern is, in my opinion, an over-complication in Laravel apps