首页 > 解决方案 > Laravel - 路由资源更新功能不起作用

问题描述

我无法在资源路由中运行 Controller > Update 功能。当我尝试将表单发送到更新时,页面返回到后面。即使更新功能完全是空的。但功能尚未触发。

我的代码:

// Controller
public function update(UserRequest $r, $id)
{
   die('asdasd');
}
// HTML
<form class="ban-form" style="visibility: hidden" action="{{ route('user.update', $user->id) }}" method="POST">
   @method('PUT')
   @csrf
</form>

标签: phplaravel

解决方案


<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

class_alias('App\Http\Controllers\HomeController', 'HomeController');
class_alias('App\Http\Controllers\AdminController', 'AdminController');
class_alias('App\Http\Controllers\FormController', 'FormController');
class_alias('App\Http\Controllers\ActionController', 'ActionController');
class_alias('App\Http\Controllers\UserController', 'UserController');

Route::get('/', 'HomeController@index')->name('home');

Route::get('giris-yap', 'HomeController@login')->name('user.login');
Route::get('kayit-ol', 'HomeController@register')->name('user.register');
Route::get('sifremi-unuttum', 'HomeController@forgotPassword')->name('user.forgot-password');
Route::get('hesabim', 'HomeController@account')->name('user.account');
Route::get('satin-al/{id}', 'HomeController@buy')->where('id','[0-9]+')->name('user.buy');
Route::get('satin-al/adim/2', 'HomeController@pay')->name('pay');
Route::get('{slug}', 'HomeController@slug')->name('slug');

Route::prefix('action')->group(function()
{

  Route::get('logout', 'ActionController@logout')->name('user.logout');

});

Route::prefix('form')->group(function()
{

  Route::post('login', 'FormController@login')->name('form.user.login');
  Route::post('forgot-password', 'FormController@forgotPassword')->name('form.user.forgot-password');
  Route::post('pay/{method}', 'FormController@pay')->where('method','(transfer|credit-card|crypto-currency)')->name('form.user.pay');
  Route::post('contact', 'FormController@contact')->name('form.contact');
  Route::post('update/pp', 'FormController@updatePP')->name('form.user.update.pp');
  Route::post('update/profile', 'FormController@updateProfile')->name('form.user.update.profile');

});

Route::prefix('admin')->group(function()
{
  Auth::routes();

  Route::get('/index', 'App\Http\Controllers\AdminController@index')->name('admin.login');

  Route::group(['middleware' => 'auth'], function () {
    Route::resource('user', 'UserController');
    Route::get('profile', ['as' => 'profile.edit', 'uses' => 'App\Http\Controllers\ProfileController@edit']);
    Route::put('profile', ['as' => 'profile.update', 'uses' => 'App\Http\Controllers\ProfileController@update']);
    Route::get('upgrade', function () {return view('pages.upgrade');})->name('upgrade');
    Route::put('profile/password', ['as' => 'profile.password', 'uses' => 'App\Http\Controllers\ProfileController@password']);
  });
});


推荐阅读