authService = $authService; } /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return $this->authService->isAuthenticated(); } /** * Run before validating data */ protected function prepareForValidation() { if (!$this->exists('slug')) { $this->merge([ 'slug' => Str::slug($this->get('title')), ]); } if (!$this->exists('date')) { $this->merge([ 'date' => Carbon::now()->toDateTime(), ]); } if (!$this->exists('summary')) { $content = $this->get('content'); $pos = -1; if (strlen($content) > 200) { $pos = strpos($content, ' ', 200); } $summary = substr($content, 0, $pos); $this->merge([ 'summary' => $summary, ]); } } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'title' => 'required|string|max:255', 'slug' => 'required|string|max:255', 'date' => 'required|date', 'summary' => 'required|string|max:1023', 'content' => 'required|string', ]; } }