Add route binder to transaction

This commit is contained in:
James Cole 2018-02-16 16:43:57 +01:00
parent 45aa76afce
commit c9f4a1eb7b
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -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;
/**