Closed adrienne closed 2 years ago
Hi Adrienne,
we have no plans to make the table names configurable, but you can easily achieve it in your project with <30 minutes of work.
Here's what to do:
'modules' => [
Vanilo\Cart\Providers\ModuleServiceProvider::class => [
'migrations' => false
]
]
php artisan vendor:publish --provider="Vanilo\Cart\Providers\ModuleServiceProvider" --tag="migrations"
This will copy the Cart Module's migrations into your app's database/
folder.
php artisan migrate
.Cart.php
and CartItem.php
files in the app/Models/
folder.Cart.php
:
class Cart extends Vanilo\Cart\Models\Cart
{
protected $table = 'your_cart_table_name';
}
CartItem.php
:
class CartItem extends Vanilo\Cart\Models\CartItem
{
protected $table = 'your_cart_items_table_name';
}
Add these lines to app/Providers/AppServiceProvider.php
:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Vanilo\Cart\Contracts\Cart as CartContract;
use Vanilo\Cart\Contracts\CartItem as CartItemContract;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
$this->app->concord->registerModel(CartContract::class, \App\Models\Cart::class);
$this->app->concord->registerModel(CartItemContract::class, \App\Models\CartItem::class);
}
}
Now you can use the cart module with your custom table names.
You can continue using the Cart
facade (it will use your models under the hood):
use Vanilo\Cart\Facades\Cart;
Cart::addItem($product);
// etc..
php artisan vendor:publish --provider="Vanilo\Cart\Providers\ModuleServiceProvider" --tag="migrations"
command. If there are new migrations, change the table names in them accordingly.@fulopattila122 - this did work, thank you!
Currently Vanilo assumes that the table name is
carts
, and there is no way to configure this. Can you make this a config setting, please?I'll try to submit a pull request.