2014-11-02 2 views
0

"getAllLikers"의 제한값에 도달하면 중지되고 "Illuminate \ Database \ Eloquent \ Builder 클래스의 개체를 문자열로 변환 할 수 없습니다"오류가 발생합니다. Laravel에서 4.2.11. 나는 rtconner (https://github.com/rtconner/laravel-likeable)에 의해 Likable 플러그인을 사용하고 있습니다. 좋아하는 사람이 한도를 초과하거나 초과하면 제대로 작동하지만 정확한 금액이면 작동하지 않습니다.Laravel 4 범위가 정확한 크기로 작동하지 않습니다.

나는이 문제를 해결하기 위해 여러 가지 시도를 해봤지만 제대로 작동하지 않는 것처럼 보입니다. 나는 또한 그것을 볼 친구가 있고 그는 해결책을 찾지 않았다.

나에게 어떤 제안이 있으십니까?

블레이드 템플릿 : 아래 코드를 참조

<h3 class="text-muted"><small>{{ Model::getLikers($id) }} like this.</small></h3> 

모델 :

public function scopeGetLikers($query, $id) { 
    $info = DB::table('likeable_likes')->where('likable_type', '=', 'Model')->where('likable_id', '=', $id)->get(); 
    $totallikes = DB::table('likeable_like_counters')->where('likable_type', '=', 'Model')->where('likable_id', '=', $id)->sum('count'); 

    if($info == null) { 
     return 'No one'; 
    } 

    $person = ''; 
    $comma = ''; 
    $int = 0; 
    $limit = 1; 

    foreach($info as $liker) { 

     if($int == 0) { 
      $comma = ''; 
     } else { 
      $comma = ', '; 
     } 

     if($int <= $limit) { 
      $person = $person . $comma . User::getUsernameByID($liker->user_id); 
     } 

     $int++; 

    } 

    if($int > $limit) { 
     return $person . ' and <a href="" id="likes" tabindex="0" role="button" data-toggle="popover" data-trigger="focus" data-content="'. Model::getAllLikers($id) . '">' . ($totallikes - $limit - 1) . ' others </a> '; 
    } 

    return $person; 
} 

public function scopeGetAllLikers($query, $id) { 
    $info = DB::table('likeable_likes')->where('likable_type', '=', 'Model')->where('likable_id', '=', $id)->get(); 

    if($info == null) { 
     return '9999999'; 
    } 

    $person = ''; 
    $comma = ''; 
    $int = 0; 
    $limit = 2; 

    foreach($info as $liker) { 

     if($int = $limit) { 
      $comma = ''; 
     } else { 
      $comma = ', '; 
     } 

     if($int > $limit) { 
      $person = $person . $comma . User::getUsernameByID($liker->user_id); 
     } 

     $int++; 

    } 

    return $person; 
} 

답변

0

는 그것을 자신을 고정! :) 그래서 여기

이 솔루션입니다 : 모든 것이 잘못된 곳이기 때문에

  • 이 범위 "GetAllLikers"을 제거.
  • "GetLikers"범위를 다시 작성하십시오 (아래 코드 참조).

    public function scopeGetLikers($query, $id) { 
    $info = DB::table('likeable_likes')->where('likable_type', '=', 'Model')->where('likable_id', '=', $id)->get(); 
    $totallikes = DB::table('likeable_like_counters')->where('likable_type', '=', 'Model')->where('likable_id', '=', $id)->sum('count'); 
    
    if($info == null) { 
        return 'No one'; 
    } 
    
    $person = ''; 
    $comma = ''; 
    $int = 0; 
    $limit = 2; 
    $persons = array(); 
    
    foreach($info as $liker) { 
        $persons[] = User::getUsernameByID($liker->user_id); 
        $int++; 
    } 
    
    if($int < $limit) { 
        $limit = $int; 
    } 
    
    $arrslice = array_slice($persons, $limit); 
    $parr = array_slice($persons, 0, $limit); 
    $miniperson = implode(', ', $parr); 
    
    $others = $totallikes - $limit; 
    
    if($int > $limit) { 
        return $miniperson . ' and <a href="" id="likes" tabindex="0" role="button" data-toggle="popover" data-trigger="focus" data-content="'. implode(', ', $arrslice) . '">' . $others . ' other' . ($others == 1 ? '' : 's') . ' </a> '; 
    } 
    
    return $miniperson; 
    
    } 
    
관련 문제