Answer the question
In order to leave comments, you need to log in
How to get multiple laravel links?
There is a table of promo codes:
Schema::create('promos', function (Blueprint $table) {
$table->id();
$table->string('code')->unique();
$table->integer('discount')->nullable();
$table->boolean('delivery_discount')->nullable();
$table->integer('cur_uses_count')->default(0);
$table->integer('max_uses_count');
$table->date('end_date');
$table->foreignId('product_id')->nullable();
$table->foreign('product_id')->references('id')->on('products');
$table->timestamps();
});
Schema::create('products', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->id();
$table->string('name')->unique();
$table->string('desc')->nullable();
$table->string('image');
$table->integer('price')->unsigned()->nullable();
$table->integer('proteins')->unsigned()->nullable();
$table->integer('fats')->unsigned()->nullable();
$table->integer('energy')->unsigned()->nullable();
$table->integer('carbo')->unsigned()->nullable();
$table->boolean('top')->default(0);
$table->boolean('visibility')->default(1);
$table->string('mutable_in');
$table->string('no_mutable_in');
$table->foreignId('category_id');
$table->timestamps();
$table->foreign('category_id')->references('id')->on('categories');
});
Schema::create('meats', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('price');
$table->string('category')->default('meat');
$table->string('desc')->nullable();
$table->foreignId('product_id');
$table->timestamps();
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
});
public function promo()
{
return $this->hasOne(Promo::class);
}
public function product()
{
return $this->belongsTo(Product::class);
}
$promo = Promo::with('product')->where('code', 'like', '%' . $request->post('code') . '%')->firstOrFail();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question