I have a problem when i am trying to update in my table
it wont updated and return
data []
Function update in Controller
public function update(StorePersonRequest $request, Person $person)
{
$person->update($request->all());
return new PersonResource($person);
}
StorePersonRequest :
class StorePersonRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'CoPe'=>'required',
'NaPe'=>'required',
'PhoPe1'=>'required',
'Corq'=>'required',
];
}
4
Answers
I Did Solve it this is my code in controller file
I remember having the same issue with postman. The problem is not on laravel but on the headers of your request. Select the
application/x-www-form-urlencoded
for headers and your body will be sent successfully.Also in the method at the top select PUT instead of POST and remove the
_method
field of your bodyFirst of all, if you are not passing any file or something, I am not sure whether its good practice to use form-data. You could have just used raw and pass a json with your data using PUT OR PATCH. Also I see that you are passing an id also, any reason for that?
Anyway, I think that all you have to do to make it works, is to put the _method on your url. So in your case it should be like this:
(or PUT if you prefer it). Right now you are not passing it as a parameter, you include it in your body request. I believe that this is your problem.
Do you have the route built out in the route folder? Either api.php or web.php like below?