laravel-validation

Laravel 5.7 - Override all() method in Request validation Class to validate route parameters?

◇◆丶佛笑我妖孽 提交于 2019-12-07 13:35:11
问题 I want to validate the route parameters in the Request validation class. I know this question has been asked many times before but According to this question I override all() method and I receive this error: Class App\Http\Requests\DestroyUserRequest does not exist I'm using Laravel 5.7. Route: Route::delete('/user/{userId}/delete', 'UserController@destroy')->name('user.destroy'); Controller: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests

Laravel Back to page with old input for validation

此生再无相见时 提交于 2019-12-07 11:58:38
问题 For the Update Profile Page I use the route as Route::get('editdriver/{data}', 'DriverController@EditDriver'); And in the controller after validation i use, return Redirect::to('editdriver/'.$data)->withInput()->withErrors($validation->messages()); So, the url will be http://localhost/project/editdriver/1 If i empty the value which is required in the rule and press submit the form, It shows the old data with the validation message. What i need is, It should not show the old value, which is

Laravel 'sometimes' validator fails with nested arrays

戏子无情 提交于 2019-12-07 07:07:04
问题 Am using the Laravel Validator class to do some basic validation on an array. My array : $employee['name']='name'; $employee['address']='address'; $employee['department']['department_name']='deptname'; $employee['department']['department_address']='deptaddress'; I have the validation rules as below: $rules = array( 'name'=> 'required', 'address' => 'required', 'department.department_name' => 'sometimes|required' ) And the custom messages as below : $messages = array( 'name.required' =>

How to change Laravel Validation message for max file size in MB instead of KB?

主宰稳场 提交于 2019-12-07 04:54:57
问题 Laravel comes with this validation message that shows file size in kilobytes: file' => 'The :attribute may not be greater than :max kilobytes.', I want to customize it in a way that it shows megabytes instead of kilobytes. So for the user it would look like: "The document may not be greater than 10 megabytes." How can I do that? 回答1: You can extend the validator to add your own rule and use the same logic without the conversion to kb. You can add a call to Validator::extend to your

Validating Matching Strings

限于喜欢 提交于 2019-12-07 00:20:05
问题 When I use the Validation feature in Laravel, how can I add a pre-defined strings that are allowed in an Input? For example, let's say I want the Input to contain only one of the following: foo,bar,baz , how can I do that? $validator = Validator::make($credentials, [ 'profile' => 'required|max:255', // Here I want Predefined allowed values for it ]); 回答1: It is recommended in Laravel docs to put the validation rules in an array when they get bigger and I thought 3 rules were sufficient. I

Laravel 5 __construct() argument passing error

北城以北 提交于 2019-12-06 04:18:56
So I am trying to group all my validation rules into its respective files in folders for easy maintenance. Below is how my folder structures look: Project --app --config --(more folders) --domains ----App --------Entities --------Repositories --------Services --------Validators ----Core --------Validators So what I wanted to achieve is under Core\Validators I created a LaravelValidator.php which look like this <?php namespace Core\Validators; use Validator; abstract class LaravelValidator { /** * Validator * * @var \Illuminate\Validation\Factory */ protected $validator; /** * Validation data

Laravel Back to page with old input for validation

不想你离开。 提交于 2019-12-05 23:11:04
For the Update Profile Page I use the route as Route::get('editdriver/{data}', 'DriverController@EditDriver'); And in the controller after validation i use, return Redirect::to('editdriver/'.$data)->withInput()->withErrors($validation->messages()); So, the url will be http://localhost/project/editdriver/1 If i empty the value which is required in the rule and press submit the form, It shows the old data with the validation message. What i need is, It should not show the old value, which is from the db. I even tried., return Redirect::back()->withErrors($validation->messages()); How can i do

How to validate a email address domain in Laravel?

做~自己de王妃 提交于 2019-12-05 20:20:25
In Laravel, how do I validate an email address and force it to have a suffix like g.go.edu ? If you want to accept all emails that have suffix g.go.edu , you can use as rule both email and regex rules, for example: $rules['email'] = ['email', 'regex:/(.*)g\.go\.edu$/i']; 来源: https://stackoverflow.com/questions/29720750/how-to-validate-a-email-address-domain-in-laravel

Pass old input after Form Request validation in laravel 5

这一生的挚爱 提交于 2019-12-05 15:19:42
问题 if the validation fails it's not clear to me how i could pass the old input to fill again the form. I mean, I know how to pass the data when using the Validator class and redirecting after fail with the method withInput(), but I'm trying to learn how to use Form Requests provided in laravel 5. Thanks 回答1: $username = Request::old('username'); or in view: {{ old('username') }} Read more: http://laravel.com/docs/5.0/requests#old-input 回答2: You can redirect with old data like below with

Laravel 5 Request - altering data

我是研究僧i 提交于 2019-12-05 11:25:20
I have come across an instance where I need to alter the data that needs to be validated i.e. when no slug has been submitted, create one from the title and then validate that it is unique. The request has a method replace() which is supposed to replace the input data on the request but it doesn't appear to work. Can anyone shine a light on this? This is what I have: <?php namespace Purposemedia\Pages\Http\Requests; use Dashboard\Http\Requests\Request; use Illuminate\Auth\Guard; class PageRequest extends Request { /** * [authorize description] * @return {[type]} [description] */ public