路线 ID 无效
Route Id Not working
我正在创建一个名为医生管理系统的项目。我现在陷入困境,当用户登录他的页面时,我的路由功能会获取特定的 ID,然后显示他的信息。但是当我登录时它没有得到 id & 这就是为什么它会出现一些错误但是当我手动输入 id 时它工作得很好。我没有找到为什么会这样。请大家帮帮我。
我的路线文件
Route::group([
'middleware' => 'auth'
], function() {
Route::get('/home/{profile_id}', [
'as' => 'admin',
'uses' => 'AdminController@index'
]);
Route::get('/profile/{profile_id}', array('as' =>'profile' ,'uses' => 'ProfileController@index'));
我的个人资料控制器是
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\User;
class ProfileController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($profile_id)
{
$profile = User::find($profile_id);
// if(!$profile) {
// return redirect()->route('logout')->with(['fail' => 'Profile Not Found']);
// }
return view('admin.article.index',['profile' => $profile]);
}
错误是
您没有指定正在访问什么 URL,所以我想它是 whatever_your_domain_is/profile/{id}.
显示的错误告诉您没有输入 URL 的路线。
我想你想显示登录用户的个人资料,所以实际上你不需要任何 {id} 在路由中,你可以:
$profile = Auth::user();
return view('admin.article.index', compact('profile'));
但如果您确实想显示其他用户的个人资料,只需查看您的 URL。
我注意到的一些事情:
您的 'profile/{profile_id}' 路由在路由组之外,这是应该的方式吗?
选择一种模式来编写您的代码。您使用不同的符号编写了数组:array() 和 []。阅读编码标准(例如 https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)。
我正在创建一个名为医生管理系统的项目。我现在陷入困境,当用户登录他的页面时,我的路由功能会获取特定的 ID,然后显示他的信息。但是当我登录时它没有得到 id & 这就是为什么它会出现一些错误但是当我手动输入 id 时它工作得很好。我没有找到为什么会这样。请大家帮帮我。
我的路线文件
Route::group([
'middleware' => 'auth'
], function() {
Route::get('/home/{profile_id}', [
'as' => 'admin',
'uses' => 'AdminController@index'
]);
Route::get('/profile/{profile_id}', array('as' =>'profile' ,'uses' => 'ProfileController@index'));
我的个人资料控制器是
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\User;
class ProfileController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($profile_id)
{
$profile = User::find($profile_id);
// if(!$profile) {
// return redirect()->route('logout')->with(['fail' => 'Profile Not Found']);
// }
return view('admin.article.index',['profile' => $profile]);
}
错误是
您没有指定正在访问什么 URL,所以我想它是 whatever_your_domain_is/profile/{id}.
显示的错误告诉您没有输入 URL 的路线。
我想你想显示登录用户的个人资料,所以实际上你不需要任何 {id} 在路由中,你可以:
$profile = Auth::user();
return view('admin.article.index', compact('profile'));
但如果您确实想显示其他用户的个人资料,只需查看您的 URL。
我注意到的一些事情:
您的 'profile/{profile_id}' 路由在路由组之外,这是应该的方式吗?
选择一种模式来编写您的代码。您使用不同的符号编写了数组:array() 和 []。阅读编码标准(例如 https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)。