diff --git a/app/Http/Controllers/Dashboard/AdminPanelController.php b/app/Http/Controllers/Dashboard/AdminPanelController.php index 4850e60..5afd033 100644 --- a/app/Http/Controllers/Dashboard/AdminPanelController.php +++ b/app/Http/Controllers/Dashboard/AdminPanelController.php @@ -16,6 +16,7 @@ class AdminPanelController extends Controller private ProjectRepository $projectRepository ) { $this->categoryRepository->auth = true; + $this->projectRepository->auth = true; } public function __invoke(Request $request): InertiaResponse diff --git a/app/Http/Controllers/Dashboard/CategoryController.php b/app/Http/Controllers/Dashboard/CategoryController.php index 2636944..b26f160 100644 --- a/app/Http/Controllers/Dashboard/CategoryController.php +++ b/app/Http/Controllers/Dashboard/CategoryController.php @@ -29,12 +29,19 @@ class CategoryController public function store(CategoryRequest $request) { - $validate = $request->validated(); - if ($category = $this->categoryRepository->create($validate)) { - return redirect()->route('admin.category.update', ['category' => $category])->with('message', 'Utworzono kategorię!'); - } + // $validate = $request->validated(); + // if ($category = $this->categoryRepository->create($validate)) { + // return redirect() + // ->route('admin.category.update', compact('category')) + // ->with('message', 'Utworzono kategorię!'); + // } - return back()->withError(['message_error', 'Wystąpił błąd podczas tworzenia!']); + // return back()->withError(['message_error', 'Wystąpił błąd podczas tworzenia!']); + + $category = $this->categoryRepository->create($request->validated()); + return redirect() + ->route('admin.category.update', compact('category')) + ->with('message', 'Utworzono kategorię!'); } public function create(): View diff --git a/app/Http/Controllers/Dashboard/ProjectController.php b/app/Http/Controllers/Dashboard/ProjectController.php index e3e57ea..7e78350 100644 --- a/app/Http/Controllers/Dashboard/ProjectController.php +++ b/app/Http/Controllers/Dashboard/ProjectController.php @@ -18,15 +18,14 @@ class ProjectController $this->projectRepository->auth = true; } - public function edit(Project $project): View + public function edit(Project $project): InertiaResponse { - return view('dashboard.projects.edit', compact('project')); + return inertia('Projects/Edit', compact('project')); } public function update(ProjectRequest $request, Project $project): RedirectResponse { - $validated = $request->validated(); - if ($this->projectRepository->update($project, $validated)) { + if ($this->projectRepository->update($project, $request->validated())) { return back()->with('message', 'Zaktualizowano projekt!'); } diff --git a/app/Http/Requests/CategoryRequest.php b/app/Http/Requests/CategoryRequest.php index 3eac9bf..4ce5b04 100644 --- a/app/Http/Requests/CategoryRequest.php +++ b/app/Http/Requests/CategoryRequest.php @@ -1,34 +1,34 @@ 'required|string|min:3|max:25', 'slug' => 'required|string|min:3|max:25', 'priority' => 'required|numeric|min:0|max:10', - 'default' => 'nullable|in:yes,1,true,on', - 'visible' => 'nullable|in:yes,1,true,on' + 'default' => 'nullable|boolean', + 'visible' => 'required|boolean', ]; } + + protected function prepareForValidation(): void + { + $this->merge([ + 'default' => $this->toBoolean($this->default), + 'visible' => $this->toBoolean($this->visible), + ]); + } + + private function toBoolean($booleable): bool + { + return filter_var($booleable, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + } } diff --git a/app/Http/Requests/ProjectRequest.php b/app/Http/Requests/ProjectRequest.php index a1562f7..c1f1d33 100644 --- a/app/Http/Requests/ProjectRequest.php +++ b/app/Http/Requests/ProjectRequest.php @@ -1,27 +1,14 @@ 'required|string|min:3|max:255', @@ -37,7 +24,19 @@ class ProjectRequest extends FormRequest 'project_url' => 'nullable|string', 'project_version' => 'nullable|string', 'description' => 'nullable|string', - 'visible' => 'nullable|in:yes,1,true,on' + 'visible' => 'required|boolean' ]; } + + protected function prepareForValidation(): void + { + $this->merge([ + 'visible' => $this->toBoolean($this->visible), + ]); + } + + private function toBoolean($booleable): bool + { + return filter_var($booleable, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + } } diff --git a/app/Repository/ProjectRepository.php b/app/Repository/ProjectRepository.php index 0eb0221..a9e3562 100644 --- a/app/Repository/ProjectRepository.php +++ b/app/Repository/ProjectRepository.php @@ -8,7 +8,6 @@ use App\Http\Resources\ProjectCollection; use App\Http\Resources\ProjectResource; use App\Models\Project; use App\Repository\Interfaces\ProjectRepository as ProjectRepositoryInterface; -use Illuminate\Database\Query\Builder; use Illuminate\Support\Collection; class ProjectRepository implements ProjectRepositoryInterface @@ -104,11 +103,7 @@ class ProjectRepository implements ProjectRepositoryInterface else $toSave['update_date'] = null; - if ( - isset($data['visible']) && - in_array($data['visible'], ['yes', 'on', 1, true]) - ) $toSave['visible'] = true; - else $toSave['visible'] = false; + $toSave['visible'] = $data['visible']; return $toSave; } diff --git a/package-lock.json b/package-lock.json index c659d41..690477e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "kamilcraft-api2", + "name": "application", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/resources/js/Pages/Projects/Create.vue b/resources/js/Pages/Projects/Create.vue index 5a76d7f..c43bd80 100644 --- a/resources/js/Pages/Projects/Create.vue +++ b/resources/js/Pages/Projects/Create.vue @@ -14,8 +14,12 @@ const form = useForm({ project_url: null, project_version: null, description: null, - visible: false, + visible: Boolean(false), }); + +function createProject() { + form.post('/dashboard/project'); +}