PHP code example of entrie-cloud / laravel-cockpit
1. Go to this page and download the library: Download entrie-cloud/laravel-cockpit 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/ */
entrie-cloud / laravel-cockpit example snippets
return [
// The default connection name to use for Cockpit API calls.
'default' => env('COCKPIT_CONNECTION', 'main'),
// The URL path prefix to trigger cache clearing for Cockpit cache.
'cache_clear_path' => env('COCKPIT_CACHE_CLEAR_PATH', '/cockpit-cache-clear'),
// The query parameter name used to bypass caching when accessing Cockpit API routes.
'cache_ignore_query' => env('COCKPIT_CACHE_IGNORE_QUERY', 'cockpit-cache-ignore'),
// List of available connections to Cockpit instances.
'connections' => [
// The main connection configuration for interacting with Cockpit.
'main' => [
// The base URL of the Cockpit API.
'api_url' => env('COCKPIT_API_URL'),
// The API key for authenticating requests to the Cockpit API.
'api_key' => env('COCKPIT_API_KEY'),
// The URL to access Cockpit's storage, such as uploads or assets.
'storage_url' => env('COCKPIT_STORAGE_URL'),
// Lifetime of the cache in seconds. If set to `true`, caching is enabled indefinitely.
'cache_lifetime' => env('COCKPIT_CACHE_LIFETIME', true),
// Secret key for ignoring cache when querying Cockpit via `cache_ignore_query`.
'cache_ignore_secret' => env('COCKPIT_CACHE_IGNORE_SECRET'),
// Secret key for clearing Cockpit cache via `cache_clear_path`.
'cache_clear_secret' => env('COCKPIT_CACHE_CLEAR_SECRET'),
],
],
];
// Also have alias `LaravelCockpit`
use EntrieCloud\LaravelCockpit\Facades\LaravelCockpit;
// GET request
$data = LaravelCockpit::get('/path/to/resource');
$data = LaravelCockpit::get('/path/to/resource', ['sort' => ['order' => -1]]);
// POST request
$result = LaravelCockpit::post('/path/to/resource', ['email' => '[email protected]']);
// DELETE request
$result = LaravelCockpit::delete('/path/to/resource');
// GET request without caching
$data = LaravelCockpit::getWithoutCache('/path/to/resource');
$data = LaravelCockpit::ignoreCache()->get('/path/to/resource');
// Clear cache for default connection
LaravelCockpit::flushCache();
// Clear cache for specific connection
LaravelCockpit::connection('secondary')->flushCache();
// Clear cache for all connections
LaravelCockpit::pruneCache();
$data = LaravelCockpit::get('/path/to/resource');
// Return full url to resource
$avatarUrl = LaravelCockpit::storage($data['avatar'])
// Return full url to resource on specific connection
$avatarUrl = LaravelCockpit::connection('secondary')->storage($data['avatar'])