I dont see any need of creating inventory table separately. You can simply add inventory column in products table. Add to that when new piece of the same product is added and subtract from it when a product is sold.
Schema::create('products', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('sku');
$table->unsignedInteger('barcode');
$table->string('name');
$table->text('description')->nullable();
$table->unsignedInteger('client_price');
$table->unsignedInteger('seller_price');
$table->text('image')->nullable();'
$table->unsignedSmallInteger('inventory');
$table->timestamps();
});
If there is a scenario where quantity could be changed, then in that case you should create another inventory table. When quantity is changed, just add another record and set updated_at timestamp. You can keep track of changes in inventory and retrieve the record with latest timestamp to know the current inventory.
Schema::create('inventory', function(Blueprint $table) {
$primary(['product_id','updated_at']);
$table->unsignedInteger('product_id');
$table->foreign('product_id')->references('id')->on('products');
$table->smallUnsignedInteger('quantity');
$table->timestamp('updated_at');
});
You can take it one step further. You can add a nullable column sale_id. Keep the sale_id null when user changes the inventory. If a product is sold, then pass that ID to inventory table while updating the quantity. This way you can find the exact sale transaction that caused the inventory change !
Schema::create('inventory', function(Blueprint $table) {
$primary(['product_id','updated_at']);
$table->unsignedInteger('product_id');
$table->foreign('product_id')->references('id')->on('products');
$table->unsignedInteger('sale_id')->nullable();
$table->foreign('sale_id')->references('id')->on('sales');
$table->smallUnsignedInteger('quantity');
$table->timestamp('updated_at');
});