Summer Sale! All accounts are 50% off this week.

raloseq's avatar

The PUT method is not supported for this route. Supported methods: GET, HEAD, POST.

I have test

    $this->withoutExceptionHandling();

    $user = User::factory()->create();
    $this->actingAs($user);
    $client = Clients::factory()->create();
    
    $response = $this->json('PUT', "/clients/$client->id", [
        'name' => 'Jan',
        'surname' => 'Kowalski',
        'NIP' => '5019281771',
        'company_name' => 'Firma A',
        'phone' => '123456789',
        'email' => '[email protected]',
        'user_id' => $user->id
    ]);

    $response->assertStatus(302);

This is my route:

Route::resource('clients', ClientsController::class);

I have @method('PUT') in form. Why im getting error The PUT method is not supported for this route. Supported methods: GET, HEAD, POST while running tests? I was trying to dump $client but i don't know how to dump something in tests.

0 likes
7 replies
raloseq's avatar

Ok so why i don't see id there? this is dd($client)

#attributes: array:9 [ "name" => "Aleksander" "surname" => "Nowak" "NIP" => "8932948512" "company_name" => "Wójcik i syn" "phone" => "188656756" "email" => "[email protected]" "user_id" => 27 "updated_at" => "2022-11-21 08:33:00" "created_at" => "2022-11-21 08:33:00" ]

raloseq's avatar
class Clients extends Model
{
    use HasFactory;

    protected $table = 'clients';
    public $incrementing = false;

    protected $fillable = [
        'name', 'surname', 'phone', 'email', 'NIP', 'company_name'
    ];

    public function client_address()
    {
        return $this->hasOne(ClientAddress::class, 'client_id', 'id');
    }

    public function service_orders()
    {
        return $this->hasMany(ServiceOrders::class, 'client_id', 'id');
    }
}

Factory:

class ClientsFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition()
    { 
        return [
            'name' => $this->faker->firstName(),
            'surname' => $this->faker->lastName(),
            'NIP' => $this->faker->numerify('##########'),
            'company_name' => $this->faker->company(),
            'phone' => $this->faker->unique()->numerify('#########'),
            'email' => $this->faker->unique()->safeEmail(),
            'user_id' => User::all()->random()->id,
        ];
    }
}
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@raloseq You are telling it to not add an ID ? And the factory does not add one either

1 like
raloseq's avatar

@Sinnbeck this is the problem i guess

public $incrementing = false;

i deleted this and it started works

Sinnbeck's avatar

@raloseq Exactly. You were telling laravel not to handle incrementing ids

1 like

Please or to participate in this conversation.