2014-01-19 31 views
0

我想在此代碼塊使用AND以及&&Laravel運算符AND/&& - 如何使用它們?

public function show($id) 
{ 

    $user = Auth::user()->id; 
    $userEmail = Auth::user()->email; 
    $share = Share::where('sbj_id', $id)->first(); 

    if ($share->sbj_id == $id && $share->email == $userEmail) { 

     $items = Item::where('project_id', $id) 
     ->orderBy("created_at", "desc") 
     ->groupBy('label_name') 
     ->get(); 

     $sbj = Sbj::find($id); 
     $allSbj = Sbj::where('user_id', $user)->orderBy("created_at", "desc")->get(); 
     $labels = Label::all(); 
     $pages = Page::where('project_id', $id)->orderBy('created_at', 'desc')->get(); 
     $people = Friend::where('sbj_id', $id)->orderBy("created_at", "desc")->get(); 
     $myPeeps = Contact::where('my_id', $user)->get(); 

     return View::make('sbjs.show', compact('sbj', 'pages', 'labels', 'people', 'myPeeps', 'allSbj', 'items')); 

    } else { 

     return Redirect::action ('[email protected]'); 
    } 


} 

不過,我看網上,看是否&&AND在Lavavel支持在這方面,但沒有成功。我的應用正在將用戶帶到ELSE操作。

任何想法?

+2

&&和AND是PHP本身的一部分,不僅僅是Laravel ...我會檢查$ userEmail和$ share-> email的值是你期望的... – Jon

回答

0

我剛剛添加了Eloquent語句到IF條件,它工作正常......不知道爲什麼它不評估。