Feat(Routes file & Student CRUD's first mehods) #25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request:
1 - According an approach by @elpupas, creates a routes file named v1.php instead of api.php (v1 stands for version 1) and modifies accordingly the file RouteServiceProvider.php, to indicate this file's location and to set API calls prefixes (api/v1).
2 - Studying and developing an approach by @androsrivas, this pull request sets an abstract class named UserRequest that extends FormRequest and defines User's register validation rules.
In this abstract class, we have overwritten the method failedValidation(...) from original FormRequest class, in order to send validation errors messages to API calls when needed.
To Store Admins, Students or Recruiters, other Form Requests will be created extending User Request and setting new validation register rules for each case.
A first version of StoreStudentRequest is already included in this commit. Notice that, in order to send all validation rules to the Controller when required, we've had to modify the function rules(). Now it will return an array merging the Parent::rules with this class own validation rules.
With this approach:
a) Store methods in each model's controller are simpler.
b) Each StoreModelRequest is also simpler, as it doesn't have to rewrite User validation rules, it just has to call for them.
3 - In Store methods, we create a $user and then, we a create a $user -> student (the relation being previously defined in the Models...). This way the foreign Key is set automatically. This system can be applied to admins and recruiters.
As two entities must be created, a DB::transaction is implemented to avoid database inconsistency, following a proposal by @CloudSalander.