for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Spatie\ValidationRules\Rules;
use Illuminate\Support\Facades\Auth;
use Illuminate\Contracts\Validation\Rule;
class Authorized implements Rule
{
/** @var string */
protected $ability;
/** @var array */
protected $arguments;
public function __construct(string $ability, string $className)
$this->ability = $ability;
$this->className = $className;
className
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
public function passes($attribute, $value)
if (! $user = Auth::user()) {
return false;
if (! $model = $this->className::find($value)) {
return $user->can($this->ability, $model);
public function message()
return __('validationRules.authorized');
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: