In this extension andersao/l5-repository.How to use the validator correctly?
Generally we will use Form Request Validation . but I see Validator Class .Form Request Validation.what is it used for? Thank you!
In this extension andersao/l5-repository.How to use the validator correctly?
Generally we will use Form Request Validation . but I see Validator Class .Form Request Validation.what is it used for? Thank you!
I have the impression that you are mixing concepts here. I will try to clarify them so you can understand the difference.
The andersao/l5-repository package is designed to help Laravel developers to use the repository pattern, which is a software design pattern.
Here is an explanation/definition of the repository pattern from the Microsoft ASP.NET Documentation (taken from the article Repository pattern with ASP.NET Core):
The repository pattern is a design pattern that isolates data access behind interface abstractions. Connecting to the database and manipulating data storage objects is performed through methods provided by the interface's implementation. Consequently, there's no need for calling code to deal with database concerns, such as connections, commands, and readers.
Put more simply, as twoflower explained it in one of his answers :
Basically, repository hides the details of how exactly the data is being fetched/persisted from/to the database. Under the covers:
The repository pattern adds a layer of abstraction in your application. From the Abstraction layer Wikipedia article:
In computing, an abstraction layer or abstraction level is a way of hiding the implementation details of a particular set of functionality [...].
Then an abstraction layer has no reason to know about or trust the data outside his scope. That is why it is better to validate the data entering the layer.
The andersao/l5-repository package includes a validator that validates the data passed to the repository. To use this validator, you write "Validator Classes".
"Form Request Validation" is a way to validate incoming requests with the Laravel framework. It is designed to validate data coming from a HTTP request.
So both are made for validating data, but at different levels in your Laravel application.