Replace Laravel binder with own binder. This will save in queries and increase security.

This commit is contained in:
James Cole
2017-12-25 08:45:23 +01:00
parent 96ccce5db3
commit bf390b65d9
37 changed files with 1671 additions and 142 deletions

View File

@@ -51,19 +51,24 @@ class TransactionCurrency extends Model
protected $fillable = ['name', 'code', 'symbol', 'decimal_places'];
/**
* @param TransactionCurrency $currency
* @param string $value
*
* @return TransactionCurrency
*/
public static function routeBinder(TransactionCurrency $currency)
public static function routeBinder(string $value): TransactionCurrency
{
if (auth()->check()) {
return $currency;
$currencyId = intval($value);
$currency = TransactionCurrency::find($currencyId);
if (!is_null($currency)) {
return $currency;
}
}
throw new NotFoundHttpException;
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function transactionJournals()