• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

182
Views
How to check if user has selected multiple checkboxes

I am working on a Laravel 5.8 project which is an Online Store. and in this project, I wanted to add "Printing Order Factors" feature for Admins.

So I have made a form like this:

<form method="POST" action="{{ route('orders.newprint') }}">
    @csrf
    @forelse($orders as $order)
    <tr>
        <td><input class="form-check-input" name="orderCheck[]" type="checkbox" value="{{ $order->ord_id }}">&nbsp;</td>
        <td>{{ $order->ord_id }}</td>
        <td>{{ $order->status_label }}</td>
        <td>{{ $order->customer_name }}</td>
        <td>{{ $order->ord_total }}</td>
    </tr>
    @empty
        <td colspan="7" class="text-center">No order to show</td>
    @endforelse
</form>

So basically admins can select multiple orders like this:

enter image description here

And I'm trying to send order ids as an array:

<input class="form-check-input" name="orderCheck[]" type="checkbox" value="{{ $order->ord_id }}">

Now at the Controller, I need to check if user has selected multiple orders or not

public function prnpriview(Request $request)
    {
        if(!empty($request->input('actions'))){
            if($request->input('actions')=='print_factors'){
                if(USER SELECTES MORE THAN ONE CHECKBOX) { 
                    ...
                    return view('admin.shop.orders.newprint', compact('args'));
                }else{
                    return back();
                }
            }
        }else{
            return back();
        }
    }

So how to check if user has selected multiple checkboxes (more than one checkbox) or not ?

I would really appreciate any idea or suggestion from you guys about this...

Thanks.

about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

$request->orderCheck will be in an array, so you can use count()

$checked = $request->input('orderCheck',[]);// if checkbox is not checked than return empty array
if(count($checked) > 1) { 
    return view('admin.shop.orders.newprint', compact('args'));
}else{
    return back();
about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error