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

@@ -52,21 +52,24 @@ class RuleGroup extends Model
protected $fillable = ['user_id', 'order', 'title', 'description', 'active'];
/**
* @param RuleGroup $value
* @param string $value
*
* @return RuleGroup
*/
public static function routeBinder(RuleGroup $value)
public static function routeBinder(string $value): RuleGroup
{
if (auth()->check()) {
if (intval($value->user_id) === auth()->user()->id) {
return $value;
$ruleGroupId = intval($value);
$ruleGroup = auth()->user()->ruleGroups()->find($ruleGroupId);
if (!is_null($ruleGroup)) {
return $ruleGroup;
}
}
throw new NotFoundHttpException;
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function rules()
@@ -75,6 +78,7 @@ class RuleGroup extends Model
}
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()