To get cookies in October CMS, you can follow these steps:
- Import Illuminate\Cookie\CookieJar and Illuminate\Cookie\CookieServiceProvider in your class file.
use Illuminate\Cookie\CookieJar; use Illuminate\Cookie\CookieServiceProvider;
- Register the CookieServiceProvider in the register() method of your plugin or module's service provider.
$this->app->register(CookieServiceProvider::class);
- Use the CookieJar class to set a cookie with the desired values. You can do this in your component's onRun() method or wherever it is appropriate.
$cookieJar = app(CookieJar::class); $cookieJar->queue('cookie_name', 'cookie_value', $minutes); // Replace 'cookie_name' and 'cookie_value' with your desired values, and $minutes with an integer representing the cookie duration in minutes. $cookieJar->queue('another_cookie', 'another_value', $minutes); // You can set multiple cookies in the same request.
- To retrieve the cookie values, you can use the Cookie facade in your component's code.
use Illuminate\Support\Facades\Cookie;
...
$cookieValue = Cookie::get('cookie_name'); // Replace 'cookie_name' with the name of the cookie you want to retrieve.
Note: Make sure you have set the cookie before trying to retrieve it using the Cookie
facade.
By following these steps, you can set and retrieve cookies in your October CMS project.
How to create a plugin in October CMS?
To create a plugin in October CMS, you need to follow these steps:
- Install October CMS: Follow the official installation guide to set up a local development environment for October CMS.
- Create a Plugin: Navigate to the plugins directory in your October CMS installation. Inside the plugins directory, create a new directory for your plugin. For example, if your plugin is named "MyPlugin", create a directory named "MyVendor/MyPlugin".
- Define the Plugin: Inside the plugin directory, create a file named Plugin.php. This file will define the plugin and its properties. Here is an example of a Plugin.php file: