PHP code example of botnetdobbs / laravel-luminous
1. Go to this page and download the library: Download botnetdobbs/laravel-luminous library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
botnetdobbs / laravel-luminous example snippets
use Botnetdobbs\Luminous\Attributes\ApiTag;
use Botnetdobbs\Luminous\Attributes\ApiSecurity;
use Botnetdobbs\Luminous\Attributes\ApiOperation;
use Botnetdobbs\Luminous\Attributes\ApiParam;
use Botnetdobbs\Luminous\Attributes\ApiQuery;
use Botnetdobbs\Luminous\Attributes\ApiHeader;
use Botnetdobbs\Luminous\Attributes\ApiResponse;
use Botnetdobbs\Luminous\Attributes\ApiIgnore;
#[ApiTag('Payments')]
#[ApiSecurity('bearerAuth')]
class PaymentController extends Controller
{
#[ApiOperation('List payments')]
#[ApiQuery('status', 'Filter by status', enum: ['pending', 'succeeded', 'failed'])]
#[ApiQuery('limit', 'Results per page', type: 'integer', example: 20)]
#[ApiResponse(200, PaymentResource::class, 'Payments list', paginated: true)]
public function index(Request $request): JsonResponse {}
#[ApiOperation('Get a payment')]
#[ApiParam('payment', 'Payment ID', type: 'integer', example: 42)]
#[ApiResponse(200, PaymentResource::class, 'Payment retrieved')]
#[ApiResponse(404, ErrorResource::class, 'Not found')]
public function show(Payment $payment): JsonResponse {}
#[ApiOperation('Create a payment', 'Initiates a payment. Requires an idempotency key.')]
#[ApiHeader('Idempotency-Key',
use Botnetdobbs\Luminous\Support\Shape;
class CreatePaymentRequest extends FormRequest
{
public function rules(): array
{
return [
'amount' => [' hints(): array
{
return [
'amount' => Shape::integer()
->description('Amount in minor units. 10000 = $100.00')
->example(10000),
];
}
}
use Botnetdobbs\Luminous\Attributes\ApiShape;
use Botnetdobbs\Luminous\Support\Shape;
#[ApiShape]
class PaymentResource extends JsonResource
{
public static function schema(): Shape
{
return Shape::object([
'id' => Shape::integer()->readOnly(),
'status' => Shape::enum(PaymentStatus::class)->readOnly(),
'amount' => Shape::integer()->readOnly()->description('Amount in minor units'),
'currency' => Shape::string()->readOnly()->example('USD'),
'description' => Shape::string()->nullable()->readOnly(),
'created_at' => Shape::dateTime()->readOnly(),
]);
}
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'status' => $this->status,
'amount' => $this->amount,
'currency' => $this->currency,
'description' => $this->description,
'created_at' => $this->created_at->toIso8601String(),
];
}
}