Improvements for #616 and others.

This commit is contained in:
James Cole
2017-08-23 21:21:42 +02:00
parent 1a89e379a4
commit 394e92d538
19 changed files with 383 additions and 55 deletions

View File

@@ -14,6 +14,7 @@ namespace FireflyIII\Models;
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* @property int $journalCount
@@ -36,7 +37,25 @@ class LinkType extends Model
'editable' => 'boolean',
];
public function transactionJournalLinks() {
/**
* @param $value
*
* @return mixed
* @throws NotFoundHttpException
*/
public static function routeBinder($value)
{
if (auth()->check()) {
$model = self::where('id', $value)->first();
if (!is_null($model)) {
return $model;
}
}
throw new NotFoundHttpException;
}
public function transactionJournalLinks()
{
return $this->hasMany(TransactionJournalLink::class);
}

View File

@@ -16,6 +16,7 @@ namespace FireflyIII\Models;
use Crypt;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class TransactionJournalLink
@@ -26,6 +27,28 @@ class TransactionJournalLink extends Model
{
protected $table = 'journal_links';
/**
* @param $value
*
* @return mixed
* @throws NotFoundHttpException
*/
public static function routeBinder($value)
{
if (auth()->check()) {
$model = self::where('journal_links.id', $value)
->leftJoin('transaction_journals as t_a', 't_a.id', '=', 'source_id')
->leftJoin('transaction_journals as t_b', 't_b.id', '=', 'destination_id')
->where('t_a.user_id', auth()->user()->id)
->where('t_b.user_id', auth()->user()->id)
->first(['journal_links.*']);
if (!is_null($model)) {
return $model;
}
}
throw new NotFoundHttpException;
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/