58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Dynamic;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
|
|
class ParticipantController extends Controller
|
|
{
|
|
use AuthorizesRequests;
|
|
|
|
public function update(Request $request, Dynamic $dynamic)
|
|
{
|
|
$request->validate([
|
|
'display_name' => ['required', 'string', 'max:255'],
|
|
]);
|
|
|
|
$participant = $dynamic->participants()->where('user_id', $request->user()->id)->firstOrFail();
|
|
|
|
$dynamic->participants()->updateExistingPivot($participant->id, [
|
|
'display_name' => $request->input('display_name'),
|
|
]);
|
|
|
|
return redirect()->back()->with('success', 'Display name updated successfully!');
|
|
}
|
|
|
|
public function show(Request $request, Dynamic $dynamic, User $user)
|
|
{
|
|
// Ensure both the authenticated user and the target user are in the dynamic
|
|
if (! $dynamic->participants()->where('user_id', $request->user()->id)->exists()) {
|
|
abort(403);
|
|
}
|
|
|
|
$participant = $dynamic->participants()->where('user_id', $user->id)->firstOrFail();
|
|
|
|
$mutations = $user->mutations()
|
|
->whereHas('ledger', fn ($query) => $query->where('dynamic_id', $dynamic->id))
|
|
->with('ledger')
|
|
->latest('id')
|
|
->take(10)
|
|
->get();
|
|
|
|
return Inertia::render('Dynamics/Participants/Show', [
|
|
'dynamic' => $dynamic,
|
|
'participant' => [
|
|
'id' => $user->uuid,
|
|
'name' => $user->name,
|
|
'display_name' => $participant->pivot->display_name,
|
|
'role' => $participant->pivot->role,
|
|
],
|
|
'mutations' => $mutations,
|
|
]);
|
|
}
|
|
}
|