Hello all.
The title might be a bit misleading. I am doing a personal project for my work and decided to make it with Laravel 9. I am learning it still so my terminology knowledge is not the best.
My idea is to create a simple app that would store the records for my inventory. My inventory is mostly drinks or food, so the products have expiration date. Each product can also have one or more EAN codes. What I am basically trying to do is store the expiration date on my products into database, so I know which inventory should be pushed to sell.
I understand how to do the basic CRUD functionality and storing new data is not a problem. However, I already populated my database with the products we have in the inventory (as those products most of the time won't change). My wish is that I add expiring date to the product and the location where it's stored. To do this, I would scan the barcode and based on the scanned EAN the appropriate product would be selected from the database.
Models I have so far:
Product:
public function barcodes() {
return $this->hasMany('App\Models\Barcode');
}
protected $fillable = [
'prod_id',
'prod_name',
];
Migration:
Schema::create('products', function (Blueprint $table) {
$table->id('id', 5);
$table->string('prod_id', 5)->unique();
$table->string('prod_name', 50);
$table->timestamps();
});
Barcode:
public function product() {
return $this->belongsTo('App\Models\Product');
}
protected $fillable = [
'prod_id',
'ean',
];
Migration:
Schema::create('barcodes', function (Blueprint $table) {
$table->id();
$table->string('prod_id', 5);
$table->string('ean');
$table->timestamps();
$table->foreign('prod_id')->references('prod_id')->on('products')->onDelete('cascade');
});
ExpirationDate:
protected $fillable = [
'prod_id',
'location',
'expiration_date',
'stock',
];
Migration:
Schema::create('expiration_date', function (Blueprint $table) {
$table->id();
$table->string('prod_id', 5);
$table->string('location');
$table->date('exp_date');
$table->string('stock');
$table->timestamps();
$table->foreign('prod_id')->references('prod_id')->on('products');
});
So what I tried so far is actually adding 'Expiration Date' records thru form with following fields:
- input field 'Product'
- input field 'Location'
- date field 'Expiration Date'
- input field 'Stock'
The problem I face now is that in the field 'Product' I want to enter the barcode and based on that barcode appropriate product should be selected as we are storing expiration date on Product and not Barcode.