skip to Main Content

I’m trying to set a max attribute based on the retrieved value in my database but it doesn’t seem to work for me.

These is the codes that I tried

//
<input type="number" name="entered_qty" placeholder="Enter Quantity" min="1" max="<?=$data->store_quantity?>" required>
//
<input type="number" name="entered_qty" placeholder="Enter Quantity" min="1" max="{{$data->store_quantity}}" required>

I also tried to retrieve it as value="{{$data->store_quantity}}" to see if I’m able to retrieve the value in my database and it does. Furthermore there data types in my database are int

but if I do it manually like this, it works just fine

<input type="number" name="entered_qty" placeholder="Enter Quantity" min="1" max="5" required>

this is also how I retrieve it in my database in my controller

public function products($encryption_id){
    $encrypt_id = Crypt::decrypt($encryption_id);
    $data=product::where('id',$encrypt_id)->first();

    return view("admin.products",compact("data"));
}

What should I do?

2

Answers


  1. You can validate the user using the dropdown as shown below.

      <select name="entered_qty">
        <option value="0">Select Quantity</option>
        @if(empty($data->store_quantity))
          @for ($i = 1; $i < $data->store_quantity; $i++)
            <option value="{{$i}}">{{$i}}</option>
          @endfor
        @endif
      </select>
    
    Login or Signup to reply.
  2. {{$data->store_quantity}} may not be an integer or number or may be smaller than 0.

    Try this:

    @if(is_int($data->store_quantity) && $data->store_quantity  > 0)
        <input type="number" name="entered_qty" placeholder="Enter Quantity" min="1" max="{{$data->store_quantity}}" required>
    @else
        // The data ur ($data->store_quantity) may not be an integer or it's smaller than 0...
        <p>"Error: Data received is not an integer or number or its smaller than 0"</p>
    @endif
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search