mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-05 13:43:36 +00:00
Cleanup in preparation of an overhaul.
This commit is contained in:
52
app/lib/FireflyIII/Database/Scope/AccountScope.php
Normal file
52
app/lib/FireflyIII/Database/Scope/AccountScope.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\Scope;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\ScopeInterface;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
|
||||
/**
|
||||
* Class AccountScope
|
||||
*
|
||||
* @package FireflyIII\Database\Scope
|
||||
*/
|
||||
class AccountScope implements ScopeInterface
|
||||
{
|
||||
static public $fields = ['accountRole' => 'account_role'];
|
||||
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function apply(Builder $builder)
|
||||
{
|
||||
foreach (self::$fields as $name => $field) {
|
||||
$builder->leftJoin(
|
||||
'account_meta AS ' . $field, function (JoinClause $join) use ($field, $name) {
|
||||
$join->on($field . '.account_id', '=', 'accounts.id')->where($field . '.name', '=', $name);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
//$builder->whereNull($model->getQualifiedDeletedAtColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the scope from the given Eloquent query builder.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function remove(Builder $builder)
|
||||
{
|
||||
foreach ($builder->joins as $join) {
|
||||
var_dump($join);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user