Skip to content

Instantly share code, notes, and snippets.

@OwenMelbz
Created April 9, 2025 10:13
Show Gist options
  • Save OwenMelbz/e5a910d850bed1bb161415309f9e6cf2 to your computer and use it in GitHub Desktop.
Save OwenMelbz/e5a910d850bed1bb161415309f9e6cf2 to your computer and use it in GitHub Desktop.
return SuccessResource::make($data)
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class SuccessResource extends JsonResource
{
public function __construct(mixed $message, array $meta = [])
{
if (is_array($message) && isset($message['data']) && isset($message['meta'])) {
parent::__construct($message);
} else {
parent::__construct([
'data' => is_string($message) ? __($message) : $message,
'meta' => $meta,
]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment