Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

51
Views
Is it a good idea to store shopping carts in database with Laravel

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?

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs