mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-23 15:41:24 +00:00
Working on improved configuration and automatically destroy cart on user logout
This commit is contained in:
16
src/Cart.php
16
src/Cart.php
@@ -493,7 +493,9 @@ class Cart
|
||||
*/
|
||||
private function getConnection()
|
||||
{
|
||||
return app(DatabaseManager::class)->connection(config('cart.database.connection', config('database.default')));
|
||||
$connectionName = $this->getConnectionName();
|
||||
|
||||
return app(DatabaseManager::class)->connection($connectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -505,4 +507,16 @@ class Cart
|
||||
{
|
||||
return config('cart.database.table', 'shoppingcart');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database connection name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getConnectionName()
|
||||
{
|
||||
$connection = config('cart.database.connection');
|
||||
|
||||
return is_null($connection) ? config('database.default') : $connection;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Gloudemans\Shoppingcart;
|
||||
|
||||
use Illuminate\Auth\Events\Logout;
|
||||
use Illuminate\Session\SessionManager;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class ShoppingcartServiceProvider extends ServiceProvider
|
||||
@@ -19,6 +21,14 @@ class ShoppingcartServiceProvider extends ServiceProvider
|
||||
$config = __DIR__ . '/../config/cart.php';
|
||||
$this->mergeConfigFrom($config, 'cart');
|
||||
|
||||
$this->publishes([__DIR__ . '/../config/cart.php' => config_path('cart.php')], 'config');
|
||||
|
||||
$this->app['events']->listen(Logout::class, function () {
|
||||
if ($this->app['config']->get('cart.destroy_on_logout')) {
|
||||
$this->app->make(SessionManager::class)->forget('cart');
|
||||
}
|
||||
});
|
||||
|
||||
if ( ! class_exists('CreateShoppingcartTable')) {
|
||||
// Publish the migration
|
||||
$timestamp = date('Y_m_d_His', time());
|
||||
|
||||
Reference in New Issue
Block a user