Saturday 15 May 2010

php - Laravel 4 Scope Not Working on exact amount -



php - Laravel 4 Scope Not Working on exact amount -

so problem when limit in "getalllikers" nail stops , gives me "object of class illuminate\database\eloquent\builder not converted string" error in laravel 4.2.11. using likable plugin rtconner (https://github.com/rtconner/laravel-likeable). works fine when amount of likers below or on limit, when exact amount won't work.

i have tried lot of different things seek work around can't seem create work. have got friend @ , did not either find solution.

do of have suggestions me? see code below:

blade template:

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

model:

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) { homecoming 'no one'; } $person = ''; $comma = ''; $int = 0; $limit = 1; foreach($info $liker) { if($int == 0) { $comma = ''; } else { $comma = ', '; } if($int <= $limit) { $person = $person . $comma . user::getusernamebyid($liker->user_id); } $int++; } if($int > $limit) { homecoming $person . ' , <a href="" id="likes" tabindex="0" role="button" data-toggle="popover" data-trigger="focus" data-content="'. model::getalllikers($id) . '">' . ($totallikes - $limit - 1) . ' others </a> '; } homecoming $person; } public function scopegetalllikers($query, $id) { $info = db::table('likeable_likes')->where('likable_type', '=', 'model')->where('likable_id', '=', $id)->get(); if($info == null) { homecoming '9999999'; } $person = ''; $comma = ''; $int = 0; $limit = 2; foreach($info $liker) { if($int = $limit) { $comma = ''; } else { $comma = ', '; } if($int > $limit) { $person = $person . $comma . user::getusernamebyid($liker->user_id); } $int++; } homecoming $person; }

fixed myself! :)

so here solution:

removed scope "getalllikers" because went wrong.

rewrote "getlikers" scope, see code below.

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) { homecoming 'no one'; } $person = ''; $comma = ''; $int = 0; $limit = 2; $persons = array(); foreach($info $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) { homecoming $miniperson . ' , <a href="" id="likes" tabindex="0" role="button" data-toggle="popover" data-trigger="focus" data-content="'. implode(', ', $arrslice) . '">' . $others . ' other' . ($others == 1 ? '' : 's') . ' </a> '; } homecoming $miniperson; }

php laravel laravel-4

No comments:

Post a Comment