You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
799 B
37 lines
799 B
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use \Illuminate\Http\Response;
|
|
use Illuminate\Contracts\Support\Responsable;
|
|
|
|
class Failure implements Responsable
|
|
{
|
|
public function __construct(
|
|
public ?int $code = null,
|
|
public ?string $status = null,
|
|
){}
|
|
|
|
public static function make()
|
|
{
|
|
return new static;
|
|
}
|
|
|
|
public function status(int $code, string $status)
|
|
{
|
|
$this->code = $code;
|
|
$this->status = $status;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function toResponse($request)
|
|
{
|
|
return response()->json([
|
|
'data' => [
|
|
'code' => $code = $this->code ?? Response::HTTP_INTERNAL_SERVER_ERROR,
|
|
'message' => $this->status ?? Response::$statusTexts[$code],
|
|
]
|
|
]);
|
|
}
|
|
}
|