different names in different dynamics
This commit is contained in:
@@ -54,7 +54,7 @@ class DynamicController extends Controller
|
||||
|
||||
$dynamic->load([
|
||||
'ledgers.media',
|
||||
'participants',
|
||||
'participants' => fn($query) => $query->withPivot('display_name'),
|
||||
'chat.messages.user',
|
||||
'chat.messages.media'
|
||||
]);
|
||||
|
||||
@@ -64,7 +64,7 @@ class LedgerController extends Controller
|
||||
|
||||
$activityService->updateCursor($request->user(), $ledger);
|
||||
|
||||
$dynamic->load('chat', 'participants');
|
||||
$dynamic->load(['chat', 'participants' => fn($query) => $query->withPivot('display_name')]);
|
||||
|
||||
$ledger->load([
|
||||
'media',
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Dynamic;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ParticipantController extends Controller
|
||||
{
|
||||
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!');
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ class Dynamic extends Model
|
||||
|
||||
public function participants(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'participants')->withPivot('role');
|
||||
return $this->belongsToMany(User::class, 'participants')->withPivot('role', 'display_name');
|
||||
}
|
||||
|
||||
public function ledgers(): HasMany
|
||||
|
||||
@@ -12,5 +12,6 @@ class Participant extends Pivot
|
||||
'user_id',
|
||||
'dynamic_id',
|
||||
'role',
|
||||
'display_name',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -49,6 +49,13 @@ class User extends Authenticatable implements PasskeyUser
|
||||
return $this->hasMany(ReadCursor::class);
|
||||
}
|
||||
|
||||
public function displayNameFor(Dynamic $dynamic): string
|
||||
{
|
||||
$participant = $dynamic->participants()->where('user_id', $this->id)->first();
|
||||
|
||||
return $participant?->pivot?->display_name ?? $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user