-
app/Rules/StartsWith.php
Open in GitHubuse Illuminate\Contracts\Validation\Rule; class StartsWith implements Rule { public function passes($attribute, $value) { return starts_with($value, $this->starts); } public function message() { $str = ''; if (is_array($this->starts)) { $i = 0; foreach ($this->starts as $start) { $str .= ($i !== 0 ? 'or' : null) . ' ' . $start; $i++; } } else { $str = $this->starts; } return 'The :attribute must start with ' . $str; } }
-
app/Http/Requests/ProjectRequest.php
Open in GitHubuse App\Rules\StartsWith; use Illuminate\Foundation\Http\FormRequest; class ProjectRequest extends FormRequest { public function rules() { return [ 'slack_webhook' => [ 'url', 'nullable', new StartsWith('https://hooks.slack.com/services/') ], 'discord_webhook' => [ 'url', 'nullable', new StartsWith(['https://discordapp.com/api/webhooks/', 'https://discord.com/api/webhooks/']) ], ]; } }