On the problem of laravel5.4 form validation in different scenarios

just started to use the laravel framework development, or rookies ~ a lot of do not quite understand, at present to do a function, customized a form verification class file ~ ~ for example, I am now a member module, my member controller can have many ways to use this member form verification class verification file, I would like to ask this form verification class can be divided into scenarios to verify it? Just like the TP framework, it can be divided into this field in the model until I add it, and I only validate that field when I do the editing function. A scene like this?
clipboard.png

Mar.01,2021

The simple implementation of

is that you can change required to required_if, and then define a flag to distinguish between scenarios.

Resource routing (RESTful) can refer to
https://laravel-china.org/doc.


implements different scenarios. It should take a different route, define an alias for each route, and then in the Request verification class, use Route::currentRouteName () to get the current route alias. This is a method I often use to implement different verification logic according to the route alias. In addition, there is another method. If you use Restful api , you can judge the verification logic according to the request method. Generally, create POST , update PUT or PATCH . I think there are some other ways to realize your idea. Laravel is a very powerful framework. I believe it can achieve most of the needs you need, as long as you are willing to learn about it


this problem is not solved? Verify the validity of data in json


there is no scenario concept by default in

laravel. You can use different Request to simulate scenarios to meet your needs

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e918f9-68ad8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e918f9-68ad8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?