Laravel Requests - handling request and Request validation
Questions tagged [laravel-request]
218 questions
1
vote
1 answer
Is there a way to get input values on messages function at laravel's request file?
At my registration form, i have a bool input as newCompany with values
0=register to existed company with company code
1=create new company
Using required_if validation at different fields. And if it fails throws a validation message like "The…

MuratDemirel
- 11
- 1
1
vote
2 answers
What is wrong with this form validation
I'm working with Laravel 5.8 and I have made this Controller method for creating some records inside the DB.
public function doTheUpload(Request $request)
{
try{
$request->validate([
'video' => 'nullable|mimes:mp4',
…

Pouya
- 114
- 1
- 8
- 36
1
vote
0 answers
Laravel Custom Request Class - can I define Middleware here?
So, for me the main 2 methods of adding middleware are in the routes files, api.php and web.php, or alternatively in the constructor of any Controller class.
However it occurred to me that there might be situations where I want to choose for a…

TKoL
- 13,158
- 3
- 39
- 73
1
vote
1 answer
Laravel spatie roles unique validation for multiple id during update
I created a role "Administrator" but each has one unique guard. I successfully generated them by creating custom function that replicates the web guard to sanctum. Or vice-versa depending where the role is created (e.g react frontend->sanctum…

dizon.ben
- 17
- 5
1
vote
0 answers
return or display valid options in Rule::in when fail validate in laravel
in my controller i have this validator
...
$request->validate([
'id' => ['bail', 'required', 'string'],
'live' => [Rule::in(['yes', 'no'])],
]);
...
and my response if the rule Rule::in fails is this
{
"message": "The given data…

Steve Silva
- 11
- 2
1
vote
1 answer
Laravel hasFile() return true even if file is not uploaded
If I uploaded the file works all perfectly, but when I avoid to upload it ( is optional ) I get this error:
fread(): read of 8192 bytes failed with errno=21 Is a directory
In my controller I tried to check if file exists with the function hasFile…

Roberto Remondini
- 242
- 1
- 6
- 19
1
vote
1 answer
Displaying everything after search term is deleted
I have a site that displays every post that is stored in a database with a search bar at the top.
Obviously when the user first visits the page no search term is applied and all posts are visible.
When the user then searches for a word and presses…

Frevelman
- 338
- 3
- 11
1
vote
2 answers
Laravel - Request safe method does not exist
I generated my StorePostRequest using artisan make command.
I defined rules on the rules method doing this:
public function rules()
{
return [
'title' => 'required|min:3|max:255',
'slug' => ['required', Rule::unique('posts',…

Nel
- 454
- 5
- 14
1
vote
1 answer
keep data form dynamically in laravel after submit if have field fail
how to keep all data in form dynamically in Laravel 7 after submitting and request is failing. the all form Created Dynamically after click (button Add more ) is deleted only keep the first form
and lot all old data
My questions.
1- how to keep…

Hassan Kamar
- 11
- 1
- 6
1
vote
1 answer
Laravel merge field in sub-arrays in the request
I am receiving this data from the request:
array:2 [
0 => array:3 [
"from" => 0
"to" => 5
"earned" => 0
]
1 => array:3 [
"from" => 5
"to" => 10
"earned" => 1
]
]
I would like to add brand_id to each sub-array.
I know…

Adem Tepe
- 61
- 6
1
vote
3 answers
Updating form in Laravel goes wrong
This may be a very simple question, but I can't figure it out! and that's frustrating.
I do my best to explain everything step by step.
This a small Todo list project in Laravel 8
A user can create a Project.
When user clicks on a created project,…

Mohsen
- 260
- 3
- 14
1
vote
1 answer
Why $request is empty when I send post request to Laravel from C# App?
I am trying to create a desktop app using c# that will manipulate my Laravel website's database(MySQL).
So I am creating API routes to act as a middleman. I actually solved my issue by changing the code but did not understand why it was not working…

CS Student
- 112
- 1
- 14
1
vote
1 answer
Laravel request validation in shallow nested resource
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…

Tiago Martins Peres
- 14,289
- 18
- 86
- 145
1
vote
4 answers
is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)
my problem :
i am using laravel framework php
i want validate a field witch my field sometime is File(image) and sometime is String(src of same image)
is there any shortcut or solution in Laravel ???

Fazel Saeedi
- 75
- 7
1
vote
1 answer
Laravel/React - "Call to a member function validated() on null" when creating a different FormRequest in Controller
I'm trying to validate two different types of data in a single axios call: Profile and ProfileSocial. The problem is, when I create a ProfileSocialRequest based on the second model and try to validate it, it returns Call to a member function…

brunouno
- 595
- 7
- 23