Built more binders.

This commit is contained in:
James Cole 2016-01-09 15:53:11 +01:00
parent ef4e964c94
commit caa1ff120a
3 changed files with 37 additions and 0 deletions

View File

@ -9,6 +9,9 @@ class Binder
{
protected $binders = [];
/**
* Binder constructor.
*/
public function __construct()
{
$this->binders = Domain::getBindables();

View File

@ -2,11 +2,13 @@
namespace FireflyIII\Models;
use Auth;
use Carbon\Carbon;
use Crypt;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* FireflyIII\Models\Attachment
@ -173,4 +175,15 @@ class Attachment extends Model
$this->attributes['notes'] = Crypt::encrypt($value);
}
public static function routeBinder(Attachment $value)
{
if (Auth::check()) {
if ($value->user_id == Auth::user()->id) {
return $value;
}
}
throw new NotFoundHttpException;
}
}

View File

@ -1,5 +1,6 @@
<?php namespace FireflyIII\Models;
use Auth;
use Carbon\Carbon;
use Crypt;
use FireflyIII\Support\CacheProperties;
@ -10,6 +11,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Watson\Validating\ValidatingTrait;
/**
@ -525,4 +527,23 @@ class TransactionJournal extends Model
return $this->transactionType->isOpeningBalance();
}
/**
* @param $value
* @param $route
*
* @return mixed
* @throws NotFoundHttpException
*/
public static function routeBinder($value, $route)
{
if (Auth::check()) {
$object = TransactionJournal::where('id', $value)->where('user_id', Auth::user()->id)->first();
if ($object) {
return $object;
}
}
throw new NotFoundHttpException;
}
}