-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
phoenix
committed
Jan 15, 2021
1 parent
286b5f0
commit f4150d4
Showing
5 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
namespace PhoenixLib\NovaNestedTreeAttachMany\Rules; | ||
|
||
use Illuminate\Contracts\Validation\Rule; | ||
|
||
class ArrayRules implements Rule | ||
{ | ||
public $rules = []; | ||
|
||
private $message; | ||
|
||
/** | ||
* Create a new rule instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(array $rules) | ||
{ | ||
$this->rules = $rules; | ||
} | ||
|
||
/** | ||
* Determine if the validation rule passes. | ||
* | ||
* @param string $attribute | ||
* @param mixed $value | ||
* @return bool | ||
*/ | ||
public function passes($attribute, $value) | ||
{ | ||
$input = [$attribute => json_decode($value, true)]; | ||
|
||
$this->rules = [$attribute => $this->rules]; | ||
|
||
$validator = \Validator::make($input, $this->rules, $this->messages($attribute)); | ||
|
||
$this->message = $validator->errors()->get($attribute); | ||
|
||
return $validator->passes(); | ||
} | ||
|
||
/** | ||
* Get the validation error message. | ||
* | ||
* @return string | ||
*/ | ||
public function message() | ||
{ | ||
return $this->message; | ||
} | ||
|
||
public function messages($attribute) | ||
{ | ||
return [ | ||
"size" => __('Select exactly') . ' :size', | ||
"min" => __('Select minimum of') . ' :min', | ||
"max" => __('Select maximum of') . ' :max', | ||
]; | ||
} | ||
} |