resources er uit gesloopt
This commit is contained in:
parent
ae925c7173
commit
8d95e4ee53
@ -3,10 +3,6 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\UpdateDynamicRequest;
|
||||
use App\Http\Resources\DynamicResource;
|
||||
use App\Http\Resources\LedgerResource;
|
||||
use App\Http\Resources\MessageResource;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Models\Dynamic;
|
||||
use App\Services\ActivityService;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
@ -23,7 +19,7 @@ class DynamicController extends Controller
|
||||
public function index(Request $request)
|
||||
{
|
||||
return Inertia::render('Dynamics/Index', [
|
||||
'dynamics' => DynamicResource::collection($request->user()->dynamics()->get()),
|
||||
'dynamics' => $request->user()->dynamics()->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
@ -59,10 +55,10 @@ class DynamicController extends Controller
|
||||
$dynamic->load(['ledgers.media', 'participants', 'chat']);
|
||||
|
||||
return Inertia::render('Dynamics/Show', [
|
||||
'dynamic' => new DynamicResource($dynamic),
|
||||
'ledgers' => LedgerResource::collection($dynamic->ledgers),
|
||||
'participants' => UserResource::collection($dynamic->participants),
|
||||
'messages' => MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT)),
|
||||
'dynamic' => $dynamic,
|
||||
'ledgers' => $dynamic->ledgers,
|
||||
'participants' => $dynamic->participants,
|
||||
'messages' => $dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT),
|
||||
'can' => [
|
||||
'update' => $request->user()->can('update', $dynamic),
|
||||
],
|
||||
@ -73,7 +69,7 @@ class DynamicController extends Controller
|
||||
{
|
||||
$this->authorize('view', $dynamic);
|
||||
|
||||
return MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT));
|
||||
return $dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,7 +80,7 @@ class DynamicController extends Controller
|
||||
$this->authorize('update', $dynamic);
|
||||
|
||||
return Inertia::render('Dynamics/Settings', [
|
||||
'dynamic' => new DynamicResource($dynamic),
|
||||
'dynamic' => $dynamic,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -3,11 +3,6 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreLedgerRequest;
|
||||
use App\Http\Resources\DynamicResource;
|
||||
use App\Http\Resources\LedgerResource;
|
||||
use App\Http\Resources\MessageResource;
|
||||
use App\Http\Resources\MutationResource;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Models\Dynamic;
|
||||
use App\Models\Ledger;
|
||||
use App\Services\ActivityService;
|
||||
@ -35,7 +30,7 @@ class LedgerController extends Controller
|
||||
$this->authorize('update', $dynamic);
|
||||
|
||||
return Inertia::render('Ledgers/Create', [
|
||||
'dynamic' => new DynamicResource($dynamic),
|
||||
'dynamic' => $dynamic,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -83,9 +78,9 @@ class LedgerController extends Controller
|
||||
]);
|
||||
|
||||
return Inertia::render('Ledgers/Show', [
|
||||
'dynamic' => new DynamicResource($dynamic),
|
||||
'ledger' => new LedgerResource($ledger),
|
||||
'messages' => MessageResource::collection($dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT)),
|
||||
'dynamic' => $dynamic,
|
||||
'ledger' => $ledger,
|
||||
'messages' => $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT),
|
||||
'can' => [
|
||||
'update' => $request->user()->can('update', $ledger),
|
||||
'close' => $request->user()->can('close', $ledger),
|
||||
@ -97,7 +92,7 @@ class LedgerController extends Controller
|
||||
{
|
||||
$this->authorize('view', $ledger);
|
||||
|
||||
return MessageResource::collection($dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT));
|
||||
return $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,8 +103,8 @@ class LedgerController extends Controller
|
||||
$this->authorize('update', $ledger);
|
||||
|
||||
return Inertia::render('Ledgers/Edit', [
|
||||
'dynamic' => new DynamicResource($dynamic),
|
||||
'ledger' => new LedgerResource($ledger),
|
||||
'dynamic' => $dynamic,
|
||||
'ledger' => $ledger,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ use App\Events\MessageSent;
|
||||
use App\Events\MutationCreated;
|
||||
use App\Events\MutationUpdated;
|
||||
use App\Http\Requests\StoreMutationRequest;
|
||||
use App\Http\Resources\MutationResource;
|
||||
use App\Models\Dynamic;
|
||||
use App\Models\Ledger;
|
||||
use App\Models\Mutation;
|
||||
@ -81,7 +80,7 @@ class MutationController extends Controller
|
||||
{
|
||||
$this->authorize('view', $mutation);
|
||||
|
||||
return new MutationResource($mutation);
|
||||
return $mutation;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\DynamicResource;
|
||||
use App\Models\Dynamic;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
@ -45,9 +44,9 @@ class ParticipantController extends Controller
|
||||
->get();
|
||||
|
||||
return Inertia::render('Dynamics/Participants/Show', [
|
||||
'dynamic' => new DynamicResource($dynamic),
|
||||
'dynamic' => $dynamic,
|
||||
'participant' => [
|
||||
'id' => $user->id,
|
||||
'id' => $user->uuid,
|
||||
'name' => $user->name,
|
||||
'display_name' => $participant->pivot->display_name,
|
||||
'role' => $participant->pivot->role,
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class BaseResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = parent::toArray($request);
|
||||
|
||||
if (isset($data['id']) && isset($this->uuid)) {
|
||||
$data['id'] = $this->uuid;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ChatResource extends BaseResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = parent::toArray($request);
|
||||
|
||||
if ($this->whenLoaded('messages')) {
|
||||
$data['messages'] = MessageResource::collection($this->messages);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DynamicResource extends BaseResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$result = parent::toArray($request);
|
||||
if ($this->ledgers) {
|
||||
$result['ledgers'] = LedgerResource::collection($this->ledgers);
|
||||
}
|
||||
if ($this->whenLoaded('participants')) {
|
||||
$result['participants'] = ParticipantResource::collection($this->participants);
|
||||
}
|
||||
if ($this->whenLoaded('chat')) {
|
||||
$result['chat'] = new ChatResource($this->chat);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LedgerResource extends BaseResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = parent::toArray($request);
|
||||
|
||||
$data['mutations'] = MutationResource::collection($this->whenLoaded('mutations'));
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MessageResource extends BaseResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class MutationResource extends BaseResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$data = parent::toArray($request);
|
||||
|
||||
$data['can'] = [
|
||||
'update' => $request->user()?->can('update', $this->resource) ?? false,
|
||||
'void' => $request->user()?->can('void', $this->resource) ?? false,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ParticipantResource extends BaseResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PredefinedMutationResource extends BaseResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserResource extends BaseResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
@ -105,6 +105,16 @@ class Mutation extends Model
|
||||
});
|
||||
}
|
||||
|
||||
protected $appends = ['can'];
|
||||
|
||||
public function getCanAttribute(): array
|
||||
{
|
||||
return [
|
||||
'update' => auth()->user()?->can('update', $this) ?? false,
|
||||
'void' => auth()->user()?->can('void', $this) ?? false,
|
||||
];
|
||||
}
|
||||
|
||||
public function getRouteKeyName()
|
||||
{
|
||||
return 'uuid';
|
||||
|
||||
@ -21,7 +21,7 @@ test('authenticated participant can view another participant detail page in dyna
|
||||
$response->assertInertia(fn ($page) => $page
|
||||
->component('Dynamics/Participants/Show')
|
||||
->has('dynamic')
|
||||
->where('participant.id', $participant->id)
|
||||
->where('participant.id', $participant->uuid)
|
||||
->where('participant.name', $participant->name)
|
||||
->where('participant.display_name', null)
|
||||
->where('participant.role', 'participant')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user