Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

devkon98's avatar

Update API doesnt work Laravel CRUD

Hello i have this api route in the api.php

Route::resource('/providers', EmailProvidersController::class);

And i have this code for updating the existing values from the controller

public function update(EmailProviderRequest $request, $emailProviderId)
    {
        if (!auth()->user()->hasPermissionTo('modify_email_to_providers_settings')) {
            return $this->generalError();
        }

        $validatedData = $request->validated();

        $emailProvider = EmailProvider::findOrFail($emailProviderId);

        $emailProvider->name = $validatedData['name'];
        $emailProvider->to = $validatedData['to'];
        $emailProvider->cc = $validatedData['cc'];
        
        $emailProvider->save();

        return $this->successResponse();
    }

This is the EmailProviderRequest code

class EmailProviderRequest 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
     */
    public function rules()
    {
        return [
            'Name' => 'required|string',
            'To' => 'required|string',
            'CC' => 'required|string',
        ];
    }
}

Im using postman to update the values and this is the url i insert in postman http://gps-warehouse-api.test/api/providers/3 If i use the method GET it will show me the values of ID 3 if i use POST will give me error and if i use PUT it will show me the welcome page of laravel. What am i doing wrong? The parameters im passign on the body are: Name, To, CC

0 likes
3 replies
Snapey's avatar

also, make sure the parameters you are sending are the same letter case as your validation and that you access validated data using the same casing

1 like

Please or to participate in this conversation.