PHP code example of dystcz / laravel-cookie-consent-history
1. Go to this page and download the library: Download dystcz/laravel-cookie-consent-history 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/ */
dystcz / laravel-cookie-consent-history example snippets
// routes/api.php
use Dystcz\CookieConsentHistory\CookieConsentHistoryFacade;
CookieConsentHistoryFacade::routes();
return [
/**
* The prefix for the table names.
* You can use your own prefix here, eg. company_ if it were to conflict with existing table names.
* We leave it empty, so the table name is cookie_consents by default.
*/
'table_prefix' => '',
/**
* The prefix for routes.
* There are only 2 routes, one for storing the consent data and one for retrieving.
*
* POST /cookie-consents (or your prefix) saves the consent
* GET /cookie-consents/{id} gets the consent if exists
*/
'route_prefix' => 'cookie-consents',
/**
* Model definition.
* You can extend the base model to your needs.
*/
'model' => Dystcz\CookieConsentHistory\Models\CookieConsent::class,
];
/**
* Store cookie consent data.
*
* @param StoreCookieConsentRequest $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function store(StoreCookieConsentRequest $request)
{
// Create DTO out of validated request
$data = new CookieConsentData(...$request->validated());
$consent = CookieConsentHistory::save($data);
return new JsonResponse([
'data' => $consent,
]);
}