2026-03-19 19:40:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\Project;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
|
|
class ProjectController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function index(Request $request): View
|
|
|
|
|
{
|
|
|
|
|
$projects = $request->user()
|
|
|
|
|
->projects()
|
|
|
|
|
->withCount(['issues' => fn ($q) => $q->where('status', 'unresolved')])
|
|
|
|
|
->orderBy('name')
|
|
|
|
|
->get();
|
|
|
|
|
|
|
|
|
|
return view('projects.index', compact('projects'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function create(): View
|
|
|
|
|
{
|
|
|
|
|
return view('projects.create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function store(Request $request): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'name' => 'required|string|max:255',
|
|
|
|
|
'platform' => 'nullable|string|max:50',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$project = Project::create($validated);
|
|
|
|
|
|
|
|
|
|
$request->user()->projects()->attach($project, ['role' => 'owner']);
|
|
|
|
|
|
|
|
|
|
return redirect()
|
|
|
|
|
->route('projects.settings', $project)
|
|
|
|
|
->with('status', 'Project created. Here is your DSN.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function settings(Request $request, Project $project): View
|
|
|
|
|
{
|
2026-03-21 16:13:38 +02:00
|
|
|
$this->authorize('view', $project);
|
2026-03-19 19:40:49 +02:00
|
|
|
|
|
|
|
|
return view('projects.settings', compact('project'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update(Request $request, Project $project): RedirectResponse
|
|
|
|
|
{
|
2026-03-21 16:13:38 +02:00
|
|
|
$this->authorize('update', $project);
|
2026-03-19 19:40:49 +02:00
|
|
|
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'name' => 'required|string|max:255',
|
|
|
|
|
'platform' => 'nullable|string|max:50',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$project->update($validated);
|
|
|
|
|
|
|
|
|
|
return back()->with('status', 'Project updated.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function regenerateKeys(Request $request, Project $project): RedirectResponse
|
|
|
|
|
{
|
2026-03-21 16:13:38 +02:00
|
|
|
$this->authorize('manageSettings', $project);
|
2026-03-19 19:40:49 +02:00
|
|
|
|
|
|
|
|
$project->regenerateKeys();
|
|
|
|
|
|
|
|
|
|
return back()->with('status', 'DSN keys regenerated.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function destroy(Request $request, Project $project): RedirectResponse
|
|
|
|
|
{
|
2026-03-21 16:13:38 +02:00
|
|
|
$this->authorize('delete', $project);
|
2026-03-19 19:40:49 +02:00
|
|
|
|
|
|
|
|
$project->delete();
|
|
|
|
|
|
|
|
|
|
return redirect()->route('projects.index')->with('status', 'Project deleted.');
|
|
|
|
|
}
|
|
|
|
|
}
|