2016-08-11 155 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

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