【问题标题】:404 a page not found in laravel404在laravel中找不到页面
【发布时间】:2019-12-22 16:36:38
【问题描述】:

我在尝试使用 'users/{id}' 路由时遇到 404 页面未找到,该路由 导致 ProfilesController@edit 方法

配置文件控制器:

public function edit($id){
        $user = User::findOrFail($id);
        return view('profiles.edit', compact('user'));
    }

这是我的 web.php 中的路线;

Route::get('/users/{id}', 'ProfilesController@edit')->name('user.edit');
Route::put('/users/{id}/update', 'ProfilesController@update')->name('user.update');

我的个人资料文件夹中有一个 edit.blade 文件

【问题讨论】:

  • 试图使用'profite/{id}' .. 你的路线是'users/{id}' 而不是'profite/{id}'
  • 我正在使用 users/{id} 来获取 ProfilesController
  • 那么为什么您的问题是“我在尝试使用 'profite/{id}' 路线时找不到 404 页面”
  • 您是否尝试清除视图缓存(php artisan view:clear)和路由缓存(php artisan route:clear)??
  • 用户是否存在?尝试在你的控制器中dd($user)

标签: php laravel


【解决方案1】:

将路由更改为此,调用 users/{id} 而不是 profile/{id}。否则,您可以使用下面的第二个选项来坚持您的方法。

Route::get('/users/{id}/edit', 'ProfilesController@edit')->name('user.edit');
Route::put('/users/{id}', 'ProfilesController@update')->name('user.update');

您还试图访问路由profile/{id},但我不明白的是它没有定义。您要么必须将路线更改为:

Route::get('/profile/{id}', 'ProfilesController@edit')->name('user.edit');
Route::put('/profile/{id}/update', 'ProfilesController@update')->name('user.update');

【讨论】:

  • 为什么这应该解决问题,解释你的答案。
  • 请解释你的答案我正在使用路线(/user/{id)/edit) 请向我解释获取视图的路线(profiles.view)
  • @livreson 我现在收到此错误 Facade\Ignition\Exceptions\ViewException Route [profile.update] 未定义。 (查看:C:\Users\user pc\Desktop\dkn\resources\views\profiles\edit.blade.php)请提供任何线索
  • 这可能是因为路由命名如果你看上面的代码,我们将更新路由命名为user.update而不是profile.update。请将其重命名为 ->name('profile.update');,看起来像 Route::put('/profile/{id}/update', 'ProfilesController@update')->name('profile.update');
猜你喜欢
  • 1970-01-01
  • 2021-07-29
  • 1970-01-01
  • 2016-06-22
  • 2016-10-20
  • 2013-06-28
  • 2020-02-22
  • 1970-01-01
  • 2019-05-11
相关资源
最近更新 更多