2017-04-21 20 views
0

我有一個查詢在我的控制器如何檢查laravel中的表列文件?

$checkAccountCounter = Counterlogin::where('uid', '=', $name)->first(); 

counterlogin表有列名activeidle,PWD等

if ($result[activeidle]=='y') 
    { 

    /* conditions*/ 
    } 

,但我不知道我如何檢查 laravel

中的「activeidle」值

回答

0

嘗試以下,而不是你的,如果條件。

if(count($post) && $post->activeidle=='y') { 
    // code here 
} 

這將檢查是否有任何記錄和該記錄對象activeidle列值=「Y」

0

試試這個:

public function User(Request $request) 
{ 
    $post = Posts::where('post_id', $request->session()->get('post_id'))->first(); 

    if(!count($post) == 'active') { 
     $post = Posts::firstOrNew(['post_id' => $request->session()->get('shopId')]); 
    } 
    return view('post.index')->(['post' => $post]); or 
    return view('post.index',compact('post')); 
}