Author::with('user')->latest()->paginate(25)]); } public function create(): View { return view('authors::admin.form', ['users' => User::orderBy('name')->get()]); } public function store(Request $r): RedirectResponse { Author::create($this->data($r)); return redirect()->route('administration.authors.index')->with('status', 'Author created.'); } public function edit(Author $author): View { return view('authors::admin.form', ['record' => $author, 'users' => User::orderBy('name')->get()]); } public function update(Request $r, Author $author): RedirectResponse { $author->update($this->data($r)); return redirect()->route('administration.authors.index')->with('status', 'Author updated.'); } public function destroy(Author $author): RedirectResponse { $author->delete(); return back()->with('status', 'Author deleted.'); } private function data(Request $r): array { $d = $r->validate(['user_id' => ['nullable', 'exists:users,id'], 'name' => ['required', 'string', 'max:255'], 'slug' => ['required', 'string', 'max:255'], 'job_title' => ['nullable', 'string', 'max:255'], 'biography' => ['nullable', 'string'], 'avatar_path' => ['nullable', 'string', 'max:255'], 'meta_title' => ['nullable', 'string', 'max:255'], 'meta_description' => ['nullable', 'string'], 'is_active' => ['sometimes', 'boolean']]); $d['is_active'] = $r->boolean('is_active'); return $d; } }