Category : laravel-formrequest

I find something lost… The problem I need to construct 2 custom FormRequest from 1 normal Request Let’s suppose this fake scenario First FormRequest StoreClientRequest Second FormRequest UpdateClientRequest On the Controller: public function store(Request $request){ //Do something… $firstRequest = new StoreClientRequest($request); $secondRequest = new UpdateClientRequest($request); } Are there way to make something similar to this ..

Read more

I’ve created a custom form request with php aritisan make:request, I have added in validation rules: public function rules() { return [ ‘first_name’ => ‘required|string’, ‘last_name’ => ‘required|string’, … ’email’ => ’email|unique:auth_user,email’, ‘password’ => [‘required’, ‘confirmed’, Password::min(8)], ‘password_confirmation’ => ‘required|string|min:8’, ]; } However, it redirects me to the index page. This is my function: public ..

Read more

I am using FormRequest to validate data. I know this question was asked many times and community try to solve this issue in many ways but none of them solve my problem. Reference links are attached. In FormRequest class AbcRequest extends FormRequest { public function authorize(){ return true; } public function rules() { return [ ..

Read more

I use custom request classes which extend Laravavel’s FormRequest (User Guide, API Documentaion) in order to validate the input parameters, and to authorize the request. The skeleton looks like this: class MyRequest extends FormRequest { /** * Determines if the user is authorized to make this request. */ public function authorize(): bool { // TODO: ..

Read more

I’m using form request to validate data into update method. I’m trying to validate email as a unique value expect requested user email like this public function rules() { $user = $this->user(); return [ ‘name’ => ‘required|max:255|string’, ’email’ => ‘required|email|max:255|unique:users,email,’.$user->id, ‘restaurant’ => ‘required’, ]; } But it doesn’t work, how to access requested user id ..

Read more

I ‘m trying to implement a cast method in a formRequest just after validation, using passedValidation() function. Everything looks good but the cast made in passedValidation() don’t appear in $request->validated(), but is visible in $request->all(). My form request <?php namespace AppHttpRequestsModelsCompany; use AppHttpRequestsCustomFormRequest; use IlluminateSupportFacadesAuth; use PropaganistasLaravelPhonePhoneNumber; class CompanyFormRequest extends CustomFormRequest { protected function prepareForValidation() ..

Read more

how to use laravel FormRequest prepareForValidation method for multiple array of objects? curl -i -X POST -H’Content-Type: application/json’ -H’Accept: application/json’ -H’Authorization: Bearer PLKKSDSDSD….’ //array of objects -d'[{ "account_id": "ABC", }, { "account_id": "DEF", }]’ https://domain/api/account protected function prepareForValidation() { $account_id = $this->account_id; $account = Account::select(‘id’)->where(‘name’, $account_id)->first(); $this->merge([ ‘account_id’ => is_null($account) ? 0 : $account->id, ]); ..

Read more

I am trying to validate a form using form request like so. /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ ‘foo_required’ => [‘boolean’, ‘nullable’], ‘foo_id’ => [‘bail’, ‘required_if:foo_required,true’, new UniqueVendorId(request()->input(‘dest’), request()->input(‘cus_id’))], ]; } The above is my form request rules, where ..

Read more

Morning, I have form with dynamics rows. I would like to use FormRequest to validate data rows. My form: <td> <input class="form-control form-control-sm" id="item_quantity" type="number" step="any" min="0" name="item_quantity[]" value="{{old(‘item_quantity[]’)}}">{!!$errors->first(‘item_quantity’, ‘<span class="error">:message</span>’)!!}</td> My FormRequest Code : public function rules() { return [ ‘item_quantity’ => ‘required’ ]; } Thks for your helps ! Sourc..

Read more

I have a form with dynamics rows. I would like to use FormRequest to validate data rows. How to achieve it ? Form <td> <input class="form-control form-control-sm" id="item_quantity" type="number" step="any" min="0" name="item_quantity[]" value="{{old(‘item_quantity[]’)}}"> {!!$errors->first(‘item_quantity’, ‘<span class="error">:message</span>’)!!} </td> My FormRequest Code : public function rules() { return [ ‘item_quantity’ => ‘required’ ]; } Sourc..

Read more

I have the following rules in my From Request: return [ ‘brand_id’ => ‘required|numeric’, ‘name’ => ‘required|string’, ‘wage_type_id’ => ‘required|numeric’, ‘work_days’ => ‘required|array’, ‘weekly_min’ => ‘required|numeric’, ‘weekly_max’ => ‘required|numeric’, ‘weekly_utmost’ => ‘required|numeric’, ‘daily_std’ => ‘required|numeric’, ‘daily_min’ => ‘required|numeric’, ‘daily_max’ => ‘required|numeric’, ]; One of them, work_days is supposed to be sent as an array. I ..

Read more

I’m building an API and validating the input fields with form requests . i don’t know how return messages and rules as json in store method in controller this is my store method in CategoryController : public function store(StoreCategoryRequest $request) { $validatedData = $request->all(); $category = Category::create($validatedData); return response()->json([ "success" => true, "message" => "successful", ..

Read more