Created
May 30, 2016 16:40
-
-
Save marttosc/15fbb3b2c246aa76abc15b3d3ec08e70 to your computer and use it in GitHub Desktop.
Query scope - Laravel 5.2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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