显示具体报价 - laravel

时间:2014-02-13 17:42:40

标签: laravel laravel-4

我在网站上显示特定优惠时遇到问题。此代码应仅显示来自用户的商品,其ID为url(http://mypage.pl/showall/ {$ id})。当我尝试它时,它显示没有单一报价的页面。

控制器:

        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\BikeController@getViewUsers'));

1 个答案:

答案 0 :(得分: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