-
app/Models/User.php
Open in GitHubuse Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { // public function projects() { return $this->belongsToMany(Project::class)->withPivot('owner'); } // }
-
app/Http/Controllers/ProjectController.php
Open in GitHubuse App\Models\Project; use App\Http\Requests\ProjectRequest; class ProjectController extends Controller { // public function store(ProjectRequest $request) { $project = Project::create($request->only([ 'title', 'url', 'description', 'receive_email', 'slack_webhook', 'discord_webhook', 'custom_webhook', ])); $request->user()->projects()->save($project, ['owner' => true]); return redirect()->route('panel.projects.installation', $project); } // public function edit($id) { $project = auth()->user() ->projects() ->findOrFail($id); if (!$project->isOwner()) { return redirect()->route('projects.show', $project)->withErrors([ 'You are not the main owner of this project, therefore you cannot edit the project.' ]); } return inertia('Projects/Edit', [ 'project' => $project ]); } // }
-
app/Models/Project.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Project extends Model { // public function isOwner() { return $this->pivot->owner; } // }