Category : laravel-request

I used Request to validate data public function rules () : array { return [‘order_type’ => ‘numeric|gt:0′]; } For example, my order_type=’abc’, I’ll be received 2 message in result order_type: [ ‘validate.numeric’, ‘validate.numeric.gt’ ] But I want only 1 message for both numeric validate and greater than 0 validate. And my result I want is: ..

Read more

I’m developing an application for Pharmacy Company, Products have many Batches. When New Invoice Creation. They don’t enter the same product with the same batch number in the Invoice Item List. How to validate using laravel Rule. My Blade (Dynamic Row) : <tr class="item_row" id="item-row-0"> <td> <select class="form-control boxed" name="items[0][product_id]" id="product_id0" onchange="productattribute(0)" data-width="100%" required> <option ..

Read more

On my SPA side I make http request with axios this way: createCompany(company: ICompanyCreation): Promise<ApiResponse<string|ErrorBody>>{ return instance .post<string|ErrorBody>(apiPaths.createCompany, company) .then(confirmationHandler) .catch(errorHandler); } where ICompanyCreation is: interface Contact{ firstName: string; lastName: string; email: string; phone: string; } export interface ICompanyCreation { name: string; status: Status; country: string; city: string; address: string; zipCode: number; admin: Contact; itHead: ..

Read more

Using request object validation /** * Store a new blog post. * * @param IlluminateHttpRequest $request * @return IlluminateHttpResponse */ public function input(PaymentRequest $request){ $payment=new Payment(); $payment->order_id=$request->order_id; And request class PaymentRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { ..

Read more

I have a search bar in view: {!!Form::open([‘name’=>’myForm’,’method’=>’GET’,’action’=>’[email protected]’, ‘files’=>true,’onsubmit’=>"return validateForm()"]) !!} {!! Form::submit(‘جستجو’,[‘class’=>’btn btn-info’]) !!} {!! Form::close() !!} and in route file, web.php: Route::get(‘area/search/’, ‘[email protected]’)->name(‘area.search’); AreaController: public function search(Request $request){ return " it is working" ; } but when I clicking on the button, the browser showing a blank page. when I use POST method ..

Read more

I have below type of json in my laravel request, I want to validate json object key in my laravel request file. I want to validate title value is required of data json. I found solution but it’s for controller, I want to validate it in my request file {"ID":null,"name":"Doe","first-name":"John","age":25,"data":[{"title":"title1","titleval":"title1_val"},{"title":"title2","titleval":"title2_val"}]} Sourc..

Read more

I have two resources Organizations OrganizationUsers Given that I want to create in both resources and that the creation must follow specific requirements, I’m using Request rules() and attributes(). For instance, since organizations need to have a unique name, I’m using public function rules() { return [ ‘name’ => [ ‘required’, ‘min:3’, Rule::unique((new Organization)->getTable())->ignore($this->route()->organization->id ?? ..

Read more

I’m using the following resource using shallow nesting Route::resource(‘organizations.emaildomains’, ‘OrganizationEmailDomainController’, [‘except’ => [‘show’]])->shallow(); Got the following table with two records which is the result of an index.blade.php Let’s say we want to edit tiagoperes.eu to stackoverflow.com. I’d go to the edit view change the respective field and click the save button. This is the result ..

Read more

Considering this route in web.php: Route::middleware(‘auth:sanctum’)->get(‘/test’, [TestConnections::class, ‘test’]);, Sanctum rejects it if the token is invalid (it is the case if it expired, or a bad token is given, an empty one, etc.). When Sanctum rejects a route, Guard.php‘s __invoke method returns return; so Laravel tries to reach the route "login". Indeed, Laravel shows this ..

Read more

In web.php, I have set this route: Route::middleware(‘auth:sanctum,expiration:1’)->get(‘/test’, [TestConnections::class, ‘test’]);. The middleware Sanctum’s Guard.php (https://github.com/laravel/sanctum/blob/2.x/src/Guard.php) has indeed a constructor that accepts the expiration as a parameter. I’ve expected that setting this expiration in the route’s middleware declaration was possible but my var_dump($expiration) that I’ve set in the constructor returns NULL, not 1. So this way ..

Read more

in my laravel project I extended the core Request class(AppCoreRequest), this works fine, when I call request() it resolves to this class. I also extended this one (AppCoreFormRequest). To keep this example simple, these classes are empty now. In my controller class I’m trying to the following: use AppCoreFormRequest; class MyController { public function update(FormRequest ..

Read more

I have defined this route in the web.php route file: Route::get(‘/middleware_test_user_project_change/{pro_id}/{projet_id}’, function ($pro_id, $projet_id) { return ‘test’; })->middleware(‘user.project.change’); I have defined this handle function in my middleware (which I’ve added into the kernel with the following entry: ‘user.project.change’ => AppHttpMiddlewareCheckUserProposition::class): <?php namespace AppHttpMiddleware; use Closure; use IlluminateHttpRequest; use AppModelsUser; class CheckUserProposition { /** * Handle ..

Read more

I am using Request validation to validate the user’s input. This is UpdateUser: <?php namespace AppHttpRequests; use IlluminateFoundationHttpFormRequest; use IlluminateSupportArr; use IlluminateSupportFacadesGate; class UpdateUser extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return Gate::allows(‘update-user’); } /** * Get the ..

Read more

When i submit the form is nothing happens. here is my step. php artisan make:request PostRequest <?php namespace AppHttpRequests; use IlluminateFoundationHttpFormRequest; class PostRequest extends FormRequest { public function authorize() { return true; } public function rules() { return [ ‘title’=>[‘required’,’max:255′], ‘article’=>[‘required’], ‘image’=>[‘image’] ]; } public function messages() { return [ ‘title.required’=>[‘need title’], ‘article.required’=>[‘need article’], ]; ..

Read more

My code is : … $new_request = Request::create($page, ‘GET’, $request->all(), $request->cookie()); $router = Route::dispatch($new_request); … with middlewares AppHttpMiddlewareEncryptCookies::class, IlluminateCookieMiddlewareAddQueuedCookiesToResponse::class, IlluminateSessionMiddlewareStartSession::class, The problem : A new session is created on every request on Route::dispatch call (if I exit before, no session created, after a new session is created) : new Redis key with redis driver, or ..

Read more