Answer the question
In order to leave comments, you need to log in
Discounts for different user groups (roles)?
hello everyone, I make discounts for different user groups (wholesaler, etc.). Here is the database architecture.
The essence of my implementation:
in a separate section of the admin panel, you can create, edit, delete, and make a discount available / not available. Inside the discount, I chain products
id
product_id
role_id
title
sale_price
date_start
date_end
Here is the ProductSale model
public function products()
{
return $this->hasMany(Product::class);
}
public function roles()
{
return $this->hasMany(Role::class);
}
<div class="form-group">
<label for="">Customer Group</label>
<select name="roles_id[]" class="form-control select2" multiple>
@foreach($roles as $role)
<option value="{{$role->id}}"
@isset($sale->id)
@if($role->id == $sale->user_role_id)
selected
@endif
@endisset
>{{ $role->title }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="products">Products</label>
<select name="products_id[]" id="products" class="form-control select2" multiple>
@foreach($products as $key=>$product)
<option value="{{$key}}"
@isset($sale->id)
@if($key == $sale->product_id)
selected
@endif
@endisset
>{{ $product }}</option>
@endforeach
</select>
</div>
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