This commit is contained in:
2023-07-28 12:18:13 +02:00
parent f5977c1b5d
commit d943e81da4
14 changed files with 209 additions and 69 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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!');
}

View File

@@ -1,34 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CategoryRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'name' => '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);
}
}

View File

@@ -1,27 +1,14 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ProjectRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'title' => '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);
}
}