mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
More bindings.
This commit is contained in:
@@ -12,179 +12,6 @@ use FireflyIII\Models\TransactionCurrency;
|
|||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
// budget list
|
|
||||||
Route::bind(
|
|
||||||
'budgetList',
|
|
||||||
function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$ids = explode(',', $value);
|
|
||||||
/** @var \Illuminate\Support\Collection $object */
|
|
||||||
$object = Budget::where('active', 1)
|
|
||||||
->whereIn('id', $ids)
|
|
||||||
->where('user_id', Auth::user()->id)
|
|
||||||
->get();
|
|
||||||
|
|
||||||
// add empty budget if applicable.
|
|
||||||
if (in_array('0', $ids)) {
|
|
||||||
$object->push(new Budget);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($object->count() > 0) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// category list
|
|
||||||
Route::bind(
|
|
||||||
'categoryList',
|
|
||||||
function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$ids = explode(',', $value);
|
|
||||||
/** @var \Illuminate\Support\Collection $object */
|
|
||||||
$object = Category::whereIn('id', $ids)
|
|
||||||
->where('user_id', Auth::user()->id)
|
|
||||||
->get();
|
|
||||||
|
|
||||||
// add empty budget if applicable.
|
|
||||||
if (in_array('0', $ids)) {
|
|
||||||
$object->push(new Category);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($object->count() > 0) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Route::bind(
|
|
||||||
'tj', function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$object = TransactionJournal::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
|
||||||
if ($object) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Route::bind(
|
|
||||||
'attachment', function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$object = Attachment::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
|
||||||
if ($object) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Route::bind(
|
|
||||||
'currency', function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$object = TransactionCurrency::find($value);
|
|
||||||
if ($object) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Route::bind(
|
|
||||||
'bill', function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$object = Bill::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
|
||||||
if ($object) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Route::bind(
|
|
||||||
'budget', function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$object = Budget::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
|
||||||
if ($object) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Route::bind(
|
|
||||||
'limitrepetition', function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$object = LimitRepetition::where('limit_repetitions.id', $value)
|
|
||||||
->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id')
|
|
||||||
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
|
||||||
->where('budgets.user_id', Auth::user()->id)
|
|
||||||
->first(['limit_repetitions.*']);
|
|
||||||
if ($object) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Route::bind(
|
|
||||||
'piggyBank', function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$object = PiggyBank::where('piggy_banks.id', $value)
|
|
||||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')
|
|
||||||
->where('accounts.user_id', Auth::user()->id)
|
|
||||||
->first(['piggy_banks.*']);
|
|
||||||
if ($object) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Route::bind(
|
|
||||||
'category', function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$object = Category::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
|
||||||
if ($object) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
Route::bind(
|
|
||||||
'tag', function ($value) {
|
|
||||||
if (Auth::check()) {
|
|
||||||
$object = Tag::where('id', $value)->where('user_id', Auth::user()->id)->first();
|
|
||||||
if ($object) {
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundHttpException;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
// auth routes, i think
|
// auth routes, i think
|
||||||
Route::group(
|
Route::group(
|
||||||
['middleware' => 'web'], function () {
|
['middleware' => 'web'], function () {
|
||||||
|
@@ -1,10 +1,12 @@
|
|||||||
<?php namespace FireflyIII\Models;
|
<?php namespace FireflyIII\Models;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FireflyIII\Models\Bill
|
* FireflyIII\Models\Bill
|
||||||
@@ -125,4 +127,15 @@ class Bill extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function routeBinder(Bill $value)
|
||||||
|
{
|
||||||
|
if (Auth::check()) {
|
||||||
|
if ($value->user_id == Auth::user()->id) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NotFoundHttpException;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
<?php namespace FireflyIII\Models;
|
<?php namespace FireflyIII\Models;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FireflyIII\Models\Budget
|
* FireflyIII\Models\Budget
|
||||||
@@ -123,5 +125,15 @@ class Budget extends Model
|
|||||||
return $this->belongsTo('FireflyIII\User');
|
return $this->belongsTo('FireflyIII\User');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function routeBinder(Budget $value)
|
||||||
|
{
|
||||||
|
if (Auth::check()) {
|
||||||
|
if ($value->user_id == Auth::user()->id) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NotFoundHttpException;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
<?php namespace FireflyIII\Models;
|
<?php namespace FireflyIII\Models;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FireflyIII\Models\Category
|
* FireflyIII\Models\Category
|
||||||
@@ -111,4 +113,14 @@ class Category extends Model
|
|||||||
return $this->belongsTo('FireflyIII\User');
|
return $this->belongsTo('FireflyIII\User');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function routeBinder(Category $value)
|
||||||
|
{
|
||||||
|
if (Auth::check()) {
|
||||||
|
if ($value->user_id == Auth::user()->id) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NotFoundHttpException;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
<?php namespace FireflyIII\Models;
|
<?php namespace FireflyIII\Models;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FireflyIII\Models\LimitRepetition
|
* FireflyIII\Models\LimitRepetition
|
||||||
@@ -44,4 +46,20 @@ class LimitRepetition extends Model
|
|||||||
$this->attributes['amount'] = strval(round($value, 2));
|
$this->attributes['amount'] = strval(round($value, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function routeBinder($value)
|
||||||
|
{
|
||||||
|
if (Auth::check()) {
|
||||||
|
$object = LimitRepetition::where('limit_repetitions.id', $value)
|
||||||
|
->leftjoin('budget_limits', 'budget_limits.id', '=', 'limit_repetitions.budget_limit_id')
|
||||||
|
->leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||||
|
->where('budgets.user_id', Auth::user()->id)
|
||||||
|
->first(['limit_repetitions.*']);
|
||||||
|
if ($object) {
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NotFoundHttpException;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,12 @@
|
|||||||
<?php namespace FireflyIII\Models;
|
<?php namespace FireflyIII\Models;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FireflyIII\Models\PiggyBank
|
* FireflyIII\Models\PiggyBank
|
||||||
@@ -118,4 +120,14 @@ class PiggyBank extends Model
|
|||||||
{
|
{
|
||||||
$this->attributes['targetamount'] = strval(round($value, 2));
|
$this->attributes['targetamount'] = strval(round($value, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function routeBinder(PiggyBank $value)
|
||||||
|
{
|
||||||
|
if (Auth::check()) {
|
||||||
|
if ($value->account->user_id == Auth::user()->id) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NotFoundHttpException;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
namespace FireflyIII\Models;
|
namespace FireflyIII\Models;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Watson\Validating\ValidatingTrait;
|
use Watson\Validating\ValidatingTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -166,4 +168,17 @@ class Tag extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo('FireflyIII\User');
|
return $this->belongsTo('FireflyIII\User');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function routeBinder(Tag $value)
|
||||||
|
{
|
||||||
|
if (Auth::check()) {
|
||||||
|
if ($value->user_id == Auth::user()->id) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NotFoundHttpException;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
<?php namespace FireflyIII\Models;
|
<?php namespace FireflyIII\Models;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FireflyIII\Models\TransactionCurrency
|
* FireflyIII\Models\TransactionCurrency
|
||||||
@@ -39,4 +41,15 @@ class TransactionCurrency extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany('FireflyIII\Models\TransactionJournal');
|
return $this->hasMany('FireflyIII\Models\TransactionJournal');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TransactionCurrency $currency
|
||||||
|
*/
|
||||||
|
public static function routeBinder(TransactionCurrency $currency)
|
||||||
|
{
|
||||||
|
if (Auth::check()) {
|
||||||
|
return $currency;
|
||||||
|
}
|
||||||
|
throw new NotFoundHttpException;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ class Domain
|
|||||||
'bill' => 'FireflyIII\Models\Bill',
|
'bill' => 'FireflyIII\Models\Bill',
|
||||||
'budget' => 'FireflyIII\Models\Budget',
|
'budget' => 'FireflyIII\Models\Budget',
|
||||||
'category' => 'FireflyIII\Models\Category',
|
'category' => 'FireflyIII\Models\Category',
|
||||||
'currency' => 'FireflyIII\Models\Currency',
|
'currency' => 'FireflyIII\Models\TransactionCurrency',
|
||||||
'limitrepetition' => 'FireflyIII\Models\LimitRepetition',
|
'limitrepetition' => 'FireflyIII\Models\LimitRepetition',
|
||||||
'piggyBank' => 'FireflyIII\Models\PiggyBank',
|
'piggyBank' => 'FireflyIII\Models\PiggyBank',
|
||||||
'tj' => 'FireflyIII\Models\TransactionJournal',
|
'tj' => 'FireflyIII\Models\TransactionJournal',
|
||||||
|
Reference in New Issue
Block a user