1. Go to this page and download the library: Download dantepiazza/laravel-base 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/ */
dantepiazza / laravel-base example snippets
// app/Http/Controllers/Controller.php (published stub)
namespace App\Http\Controllers;
use DantePiazza\LaravelApiResponse\ApiResponse;
abstract class Controller
{
public function __construct(protected ApiResponse $api) {}
}
class InvoiceController extends Controller
{
public function index(): JsonResponse
{
return $this->api->success('Invoices retrieved.')->data(Invoice::paginate(20))->response();
}
public function store(StoreInvoiceRequest $request): JsonResponse
{
return $this->api->created('Invoice created.')->data(Invoice::create($request->validated()))->response();
}
public function show(Invoice $invoice): JsonResponse
{
return $this->api->success()->data($invoice)->response();
}
public function destroy(Invoice $invoice): JsonResponse
{
$invoice->delete();
return $this->api->success('Invoice deleted.')->response();
}
}
use Illuminate\Support\Facades\Event;
// Single event
Event::listen('webhook.stripe.charge.succeeded', function (array $payload) {
$chargeId = $payload['data']['id'];
});
// Wildcard — all events from one source
Event::listen('webhook.convoy.*', ConvoyWebhookListener::class);
// Wildcard — every webhook regardless of source
Event::listen('webhook.*', GeneralWebhookListener::class);
[
'source' => 'stripe',
'event_type' => 'charge.succeeded',
'data' => [...], // $body['data'] if present, otherwise full body
'headers' => [...], // all request headers
'raw' => [...], // full decoded request body
]