2014-02-13 18 views
0

我遇到了在我的網站上顯示特定優惠的問題。此代碼應僅顯示來自用戶的優惠,whoose id位於網址(http://mypage.pl/showall/ {$ id})。當我嘗試它時,它會顯示沒有單個優惠的頁面。顯示具體供應信息 - laravel

控制器:

 public function getViewUsers($id) 
{ 
    $user = Sentry::getUser(); 
    $bikecreate = Bike::find($id); 
    $bikes = Bike::where($bikecreate->users_id == $user->id); 
    foreach (Province::all() as $value) { 
     $prov[$value->id] = $value->name; 
    } 
    foreach (BikeType::all() as $value) { 
     $type[$value->id] = $value->name; 
    } 
    return View::make('user.bikes.viewusers')->with('bike', $bikes)->with('province', $prov)->with('type', $type); 
} 

路線是在這裏;

Route::get('bike/viewusers/{id}', array('as' => 'bike.viewusers', 'uses' => 'App\Controllers\User\[email protected]')); 
+0

@Gaz_Edge這是現在的問題。 – user3305675

回答

0

看起來可能會有一些問題的代碼....但最明顯的是這句法:

$bikes = Bike::where($bikecreate->users_id == $user->id); 

應該

$bikes = Bike::where('users_id', '=', $user->id)->get(); 

如果我沒有錯,而不是這三行代碼:

$user = Sentry::getUser(); 
$bikecreate = Bike::find($id); 
$bikes = Bike::where($bikecreate->users_id == $user->id); 

你是什麼意思做的是:

$bikes = Bike::where('users_id', '=', $id)->get(); 

The proper syntax is available here

+0

Maby這是錯的,但它仍然無法正常工作。 – user3305675

+0

@ user3305675我只向你展示你的where()函數的語法錯誤,但是你的代碼邏輯似乎與你想做的事情沒有關係。您應該首先通過URL中的$ id獲取用戶,然後使用where()檢查具有該user_id的自行車。 – TonyArra

+0

我已經完成了,你向我展示了什麼。我也編輯了我的路線文件。現在看起來像這樣:'Route :: get('bike/viewusers/{id}',array('as'=>'bike.viewusers','uses'=>'App \ Controllers \ User \ BikeController @ getViewUsers ')) - > where('id','[0-9] +');'但頁面上仍然沒有顯示任何內容。 – user3305675