70 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| declare(strict_types=1);
 | |
| 
 | |
| namespace App\Http\Controllers\Dashboard;
 | |
| 
 | |
| use App\Http\Requests\ProjectRequest;
 | |
| use App\Models\Project;
 | |
| use App\Repository\Interfaces\ProjectRepository;
 | |
| use Illuminate\Http\RedirectResponse;
 | |
| use Inertia\Response as InertiaResponse;
 | |
| 
 | |
| class ProjectController
 | |
| {
 | |
| 
 | |
|     public function __construct(
 | |
|         private ProjectRepository $projectRepository
 | |
|     ) {
 | |
|         $this->projectRepository->auth = true;
 | |
|     }
 | |
| 
 | |
|     public function edit(Project $project): InertiaResponse
 | |
|     {
 | |
|         return inertia('Projects/Edit', compact('project'));
 | |
|     }
 | |
| 
 | |
|     public function update(ProjectRequest $request, Project $project): RedirectResponse
 | |
|     {
 | |
|         if ($this->projectRepository->update($project, $request->validated())) {
 | |
|             return back()
 | |
|                 ->with('success', 'Zaktualizowano projekt!');
 | |
|         }
 | |
| 
 | |
|         return back()
 | |
|             ->with(['error', 'Wystąpił błąd podczas aktualizacji!']);
 | |
|     }
 | |
| 
 | |
|     public function create(): InertiaResponse
 | |
|     {
 | |
|         return inertia('Projects/Create');
 | |
|     }
 | |
| 
 | |
|     public function store(ProjectRequest $request): RedirectResponse
 | |
|     {
 | |
|         $validated = $request->validated();
 | |
|         if ($project = $this->projectRepository->create($validated)) {
 | |
|             return redirect()
 | |
|                 ->route('admin.project.update', compact('project'))
 | |
|                 ->with('success', 'Utworzono projekt!');
 | |
|         }
 | |
| 
 | |
|         return back()->withError(['error', 'Wystąpił błąd podczas tworzenia!']);
 | |
|     }
 | |
| 
 | |
|     public function delete(Project $project): InertiaResponse
 | |
|     {
 | |
|         return inertia('Projects/ConfirmDelete', compact('project'));
 | |
|     }
 | |
| 
 | |
|     public function destroy(Project $project): RedirectResponse
 | |
|     {
 | |
|         $title = $project->title;
 | |
|         $project->delete();
 | |
|         return redirect()
 | |
|             ->route('admin.home')
 | |
|             ->with('info', 'Usunięto projekt "'. $title .'"');
 | |
|     }
 | |
| 
 | |
| }
 |