M
M
MaxSemenov2021-04-24 17:56:59
Laravel
MaxSemenov, 2021-04-24 17:56:59

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);
  }

the form
<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>

I can’t make an insert in any way, or I made a mistake in the database architecture, tell me?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question