mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Add some forgotten code to the mobile piggy bank controller things.
Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
@@ -51,17 +51,32 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereDeletedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereEncrypted($value)
|
||||
* @mixin \Eloquent
|
||||
* @property boolean $active
|
||||
* @property boolean $active
|
||||
* @method static \Illuminate\Database\Query\Builder|\FireflyIII\Models\PiggyBank whereActive($value)
|
||||
*/
|
||||
class PiggyBank extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'targetdate'];
|
||||
protected $fillable
|
||||
= ['name', 'account_id', 'order', 'targetamount', 'startdate', 'targetdate'];
|
||||
protected $hidden = ['targetamount_encrypted', 'encrypted'];
|
||||
protected $dates = ['created_at', 'updated_at', 'deleted_at', 'startdate', 'targetdate'];
|
||||
|
||||
/**
|
||||
* @param PiggyBank $value
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
public static function routeBinder(PiggyBank $value)
|
||||
{
|
||||
if (Auth::check()) {
|
||||
if ($value->account->user_id == Auth::user()->id) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
@@ -76,13 +91,16 @@ class PiggyBank extends Model
|
||||
*
|
||||
* @returns PiggyBankRepetition
|
||||
*/
|
||||
public function currentRelevantRep()
|
||||
public function currentRelevantRep(): PiggyBankRepetition
|
||||
{
|
||||
if (!is_null($this->currentRep)) {
|
||||
return $this->currentRep;
|
||||
}
|
||||
// repeating piggy banks are no longer supported.
|
||||
$rep = $this->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']);
|
||||
$rep = $this->piggyBankRepetitions()->first(['piggy_bank_repetitions.*']);
|
||||
if (is_null($rep)) {
|
||||
return new PiggyBankRepetition();
|
||||
}
|
||||
$this->currentRep = $rep;
|
||||
|
||||
return $rep;
|
||||
@@ -90,14 +108,6 @@ class PiggyBank extends Model
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function piggyBankRepetitions()
|
||||
{
|
||||
return $this->hasMany('FireflyIII\Models\PiggyBankRepetition');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $value
|
||||
@@ -122,6 +132,14 @@ class PiggyBank extends Model
|
||||
return $this->hasMany('FireflyIII\Models\PiggyBankEvent');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function piggyBankRepetitions()
|
||||
{
|
||||
return $this->hasMany('FireflyIII\Models\PiggyBankRepetition');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $value
|
||||
@@ -139,19 +157,4 @@ class PiggyBank extends Model
|
||||
{
|
||||
$this->attributes['targetamount'] = strval(round($value, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $value
|
||||
*
|
||||
* @return PiggyBank
|
||||
*/
|
||||
public static function routeBinder(PiggyBank $value)
|
||||
{
|
||||
if (Auth::check()) {
|
||||
if ($value->account->user_id == Auth::user()->id) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user