2016-09-30 4 views
1

지금은 내보기 페이지에 내 좋아하는 것을 표시 할 수 없는데 문제가 있습니다. 이것은 내보기 블레이드에 표시하려는 줄 (like_counter)이지만 일단 호출하면 정의되지 않은 변수 like_counter가 표시됩니다.Laravel 정의되지 않은 변수

public function getLikeCounter($post_id) { 
    $post = Post::find($post_id); 
    $number = null; 
    $like_counter = \DB::table('likes')->where('post_id', $post->id)->where('like',!$number)->count(); 
    return View::make('layouts.viewvideo', ['like_counter' => $like_counter]); 
} 

보기 :

<span class="badge">{{ $like_counter}}</span> 

경로 :

Route::get('/counter/{post_id}', [ 
'uses' => '[email protected]', 
'as' => 'counter' 

]);

도움 주셔서 감사합니다.

답변

0

NVM을 시도해보십시오

<span class="badge">{{ $post->likes->where('post_id', $post->id)->where('like', 1)->count() }}</span> 
0

뷰에 직접 추가하여 해결 ..이

return View::make('layouts.viewvideo')->with('like_counter', $like_counter); 
+0

시도해 보았지만 여전히 동일했습니다. – Arthur

+0

UI 코드 추가 – Komal

0

이 밖으로 시도 :

return view('layouts.viewvideo',compact('like_counter')); 

희망이 당신을 도와줍니다.

0

나는 문제가 코드이 라인에 생각 where 절 :

$like_counter = \DB::table('likes')->where('post_id', $post->id)->where('like',!$number)->count(); 

Laravel 5.2

변경이 :

->where('like', '!=', $number)->count(); 

DIFF : WHERE like를! = null