Skip to content

Instantly share code, notes, and snippets.

@marttosc
Created May 30, 2016 16:40
Show Gist options
  • Save marttosc/15fbb3b2c246aa76abc15b3d3ec08e70 to your computer and use it in GitHub Desktop.
Save marttosc/15fbb3b2c246aa76abc15b3d3ec08e70 to your computer and use it in GitHub Desktop.
Query scope - Laravel 5.2
<?php
namespace App\Card;
use Illuminate\Database\Eloquent\Model;
class Card extends Model
{
...
public function scopeTotalLimit($query)
{
return $query->get()->sum(function($card) {
return $card->limit;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment