Home > Back-end >  How to set retrieved value as max input value on Laravel?
How to set retrieved value as max input value on Laravel?

Time:01-08

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?

CodePudding user response:

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>

CodePudding user response:

{{$data->store_quantity}} May not be an integer or number or its smaller than 0

Try this and let me know the results:

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>
}
  • Related