mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 18:01:26 -06:00
Add route binder to transaction
This commit is contained in:
parent
45aa76afce
commit
c9f4a1eb7b
@ -26,6 +26,7 @@ use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Watson\Validating\ValidatingTrait;
|
||||
|
||||
/**
|
||||
@ -130,6 +131,25 @@ class Transaction extends Model
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
*
|
||||
* @return Transaction
|
||||
*/
|
||||
public static function routeBinder(string $value): Transaction
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$transactionId = intval($value);
|
||||
$transaction = auth()->user()->transactions()->where('transactions.id', $transactionId)
|
||||
->first(['transactions.*']);
|
||||
if (!is_null($transaction)) {
|
||||
return $transaction;
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
use SoftDeletes, ValidatingTrait;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user