php - 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>
解决方案
<?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']);
});
});
推荐阅读
- django - 创建新对象时如何更新外键上的字段?
- javascript - 更新用户生成标记的搜索结果
- php - 如何在现有 xml php 的末尾添加新节点
- python - 如何在 mpi4py 上的不同时间发送不同的东西
- apache-spark - 当 spark 动态分配为 true 时,EMR Cluster 显示过多的执行程序
- php - WordPress - 部分显示在菜单中的自定义类别
- .htaccess - 如果在 htaccess 中不同
- java - 如何将输入传递给 Kubernetes 容器内的 Java 应用程序?
- r - 根据 vcf 文件中的备用列重新排序变体效果
- javascript - Javascript:将另一个类的方法绑定到函数方法中的“this”关键字