Created
April 9, 2025 10:13
-
-
Save OwenMelbz/e5a910d850bed1bb161415309f9e6cf2 to your computer and use it in GitHub Desktop.
return SuccessResource::make($data)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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