I am developing an e-commerce website and I am expecting the users to visit the website from both mobiles and computers, so I can't store the cart in a session like in darryldecode/cart
Is it a good practice to store the cart in the database ?
like this
public function up()
{
Schema::create('cart', function (Blueprint $table) {
$table->id();
$table->integer('user_id');
$table->unsignedBigInteger('product_id');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('product_id')->references('id')->on('products')->onUpdate('cascade');
});
}
However, I have a cart that works with $.ajax that store the cart immediately in a session when the user clicks "add to cart" button. Is there any good alternatives ? Can the cart in darryldecode/cart be stored in the database directly?