2016-08-11 89 views
0

我正在创建一个名为医生管理系统的项目。我现在陷入了这种情况,当用户登录他的页面我的路由功能得到具体的ID &然后显示他的信息。但是,当我登录它没有得到编号&这就是为什么它会发生一些错误,但当我manuaaly输入ID它工作完全正常。我没有找到为什么会发生这种情况。请帮助我。路由ID不工作

我的路由文件

Route::group([ 
    'middleware' => 'auth' 
    ], function() { 


     Route::get('/home/{profile_id}', [ 
     'as' => 'admin', 
     'uses' => '[email protected]' 
    ]); 

     Route::get('/profile/{profile_id}', array('as' =>'profile' ,'uses' => '[email protected]')); 

我的个人资料的Controler是

<?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]); 
    } 

的错误是 enter image description here

回答

0

没有指定被访问什么网址,所以我想这是whatever_your_domain_is/profile/{id}

正在显示的错误告诉你没有输入URL的路由。

我想你想显示已登录用户的配置文件,所以实际上你不需要任何{ID}的路线,您可以:

$profile = Auth::user(); 
return view('admin.article.index', compact('profile')); 

但是,如果你想显示其他用户的个人资料,只需检查您的网址。

有些事情我已经注意到:

你的个人资料/ {} PROFILE_ID'路线是路由组之外,这是它应该是的方式?

选择一种模式编写代码。你已经使用不同的符号写了数组:array() and []。阅读编码标准(例如https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)。

+0

Tnx为您的帮助。它解决了我的问题 –

+0

不客气! – harrysbaraini

+0

如何使用此表示法更新我的个人档案文件中的任何信息? –