61 lines
1.3 KiB
PHP
61 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Project;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
|
|
class ProjectController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$projects = auth()->user()->projects()->latest()->get();
|
|
|
|
return Inertia::render('Projects/Index', [
|
|
'projects' => $projects,
|
|
]);
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$data = $request->validate([
|
|
'name' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
]);
|
|
|
|
auth()->user()->projects()->create($data);
|
|
|
|
return redirect()->back();
|
|
}
|
|
|
|
public function show(Project $project)
|
|
{
|
|
$project->load(['tasks.subtasks' => function ($query) {
|
|
$query->orderBy('id');
|
|
}]);
|
|
|
|
return Inertia::render('Projects/Show', [
|
|
'project' => $project,
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, Project $project)
|
|
{
|
|
$data = $request->validate([
|
|
'name' => 'required|string|max:255',
|
|
'description' => 'nullable|string',
|
|
]);
|
|
|
|
$project->update($data);
|
|
|
|
return redirect()->back();
|
|
}
|
|
|
|
public function destroy(Project $project)
|
|
{
|
|
$project->delete();
|
|
|
|
return redirect()->route('projects.index');
|
|
}
|
|
} |