Метод PUT не поддерживается для маршрута vehiculos/7676729/edit. Поддерживаемые методы: GET, HEAD.Php

Кемеровские программисты php общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Метод PUT не поддерживается для маршрута vehiculos/7676729/edit. Поддерживаемые методы: GET, HEAD.

Сообщение Anonymous »


Я пытаюсь понять PHP Laravel, но не могу понять, как выполнить эту операцию put.
По сути, у меня есть база данных, созданная с помощью artisan, и таблица для транспортных средств проста.

Код: Выделить всё

Schema::create('vehiculos', function (Blueprint $table) {
$table->string('id')->foreign('idFk')->references('id')->on('clientes')->onDelete('cascade');
$table->string('marca');
$table->string('modelo');
$table->year('anio');
$table->string('matricula')->primary();
$table->timestamps();
});
I just want to be able to change the vehicle data, of course cannot change id neither the matricula (license plate), everything goes well except using the PUT operation. Gives me this error: The PUT method is not supported for route vehiculos/7676729/edit. Supported methods: GET, HEAD.
What it confuses me is that I'm doing the exact thing at another class being Client where I update it and works like a charm, here doesn't.
This is my VehiculoController.php

Код: Выделить всё

public function update(Request $request, Vehiculo $vehiculo) {
// Define las reglas de validación
$request->validate([
'matricula' => 'required|unique:vehiculos' . $vehiculo->matricula,
'id' => 'required' .  $vehiculo->id,
'marca' => 'обязательно',
'modelo' => 'обязательно',
'anio' => 'обязательно',
] );
$vehiculo->update($request->all());
return redirect()->route('vehiculos.listar')->with('success', 'Vehiculo< br /> актуализировано с выходом.');
Мой web.php

Код: Выделить всё

Route::get('/', function () {
return view('welcome');
});

Route::get('/clientes', [ClienteController::class, 'index'])->name('clientes.index');

Route::resource('clientes', ClienteController::class)
->names([
'index' => 'clientes.listar',
'create' => 'clientes.crear',
'store' => 'clientes.guardar',
'show' => 'clientes.ver',
'edit' => 'clientes.editar',
'update' => 'clientes.actualizar',
'destroy' => 'clientes.eliminar',
]);

Route::resource('vehiculos', VehiculoController::class)
->names([
'index' => 'vehiculos.listar',
'create' => 'vehiculos.crear',
'store' => 'vehiculos.guardar',
'show' => 'vehiculos.ver',
'edit' => 'vehiculos.editar',
'update' => 'vehiculos.actualizar',
'destroy' => 'vehiculos.eliminar',
]);
My edit.blade.php

Код: Выделить всё





Editar vehiculos



Modificar vehiculo
@if (session('success'))
{{session('success')}}
@endif

@csrf
@method("PUT")
matricula:

id:

marca:

modelo:

anio:

ENVIAR

@if ($errors->all())
@foreach ($errors->all() as $error)
[list]
[*]{{$error}}
[/list]
@endforeach

@endif


And my index.blade.php

Код: Выделить всё

Lista de vehiculos
@if(session('success'))

{{ session('success') }}

@endif
[url={{ route(]Crear Nuevo vehiculo[/url]
[list]
@foreach ($vehiculos as $vehiculo)
[*]{{ $vehiculo->marca }} - {{ $vehiculo->modelo }}
[url={{ route(] id) }}">Ver[/url]
[url={{ route(] id) }}">Editar[/url]

@csrf
@method('DELETE')
Eliminar


@endforeach
[/list]
Also my routes available for vehiculos when I launch artisan route:list

Код: Выделить всё

GET|HEAD        vehiculos ................................................................ vehiculos.listar › VehiculoController@index
POST            vehiculos ...............................................................  vehiculos.guardar › VehiculoController@store
GET|HEAD        vehiculos/create ......................................................... vehiculos.crear › VehiculoController@create
GET|HEAD        vehiculos/{vehiculo} ......................................................... vehiculos.ver › VehiculoController@show
PUT|PATCH       vehiculos/{vehiculo} ................................................ vehiculos.actualizar › VehiculoController@update
DELETE          vehiculos/{vehiculo} ................................................. vehiculos.eliminar › VehiculoController@destroy
GET|HEAD        vehiculos/{vehiculo}/edit ................................................. vehiculos.editar › VehiculoController@edit
Make a PUT request and change the data, for example the year or model of the vehicle and see it change in the database, but whenever I try or change PUT to PATCH gives me the same error.
Edit: Also changing the method to PUT in this line gets the same result, but without error, it just does nothing
matricula)}}" method="POST">

Источник: https://stackoverflow.com/questions/781 ... ed-methods
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Php»