It is possible with the count function, like so:
@if (count($array) > 0)
{{-- expr --}}
@endif
Answer from Andy.Diaz on Stack OverflowItSolutionstuff
itsolutionstuff.com › post › laravel-array-length-validation-exampleexample.html
Laravel Array Length Validation Example - ItSolutionstuff.com
November 5, 2023 - Sometimes, we require to add validation for array minimum length or maximum length in laravel. user must need to add at least two array value. so Laravel provides default validation rules for array validation. we can use array, min, max, between and size rules to apply for array. You can see the simple solution with the controller code:
Array Count - Laravel - Stack Overflow
Have you tried first()? laravel.com/docs/5.6/collections#method-first. In addition, your question is not clear as to what exactly you're trying to achieve ... @OluwatobiSamuelOmisakin i need to update my database with the inputs i get from these arrays. More on stackoverflow.com
php - Laravel request is an array but not recognized by count() - Stack Overflow
I am passing an array into my controller via axios.post request. I am trying to get the length of the $request array that I am passing to the controller. More on stackoverflow.com
Laravel eloquent query to get records with array with specified length - Stack Overflow
It seems like this should be pretty simple to find the answer to but apparently not for me. I need to query a count of records where the field called bullets contains an array with a length of 5. H... More on stackoverflow.com
php - Best practice to pass many arrays and long variables to view in Laravel - Stack Overflow
As you can see, the method mostly ... for arrays. Now lets say there are like 10 variables like this. What would be the best practice to do this? There's nothing wrong with this but it's not-at-all clean. It is extremely crowded. I was wondering if maybe I could declare them somewhere else and pass the variable to the controller. ... Are they static? If so, define them in a config ... More on stackoverflow.com
DevOps Support
devopssupport.in › blog › laravel-array-length-validation
Laravel Array Length Validation – DevOps Support
September 30, 2023 - For instance, to ensure that the ‘users’ array contains no more than three elements, use the validation rule like this. ... Sometimes, you may require an array to have a length within a specific range. Laravel’s between rule is the perfect tool for this job.
Arievisser
arievisser.com › blog › validating-array-lengths-in-laravel
Validating Array Lengths in Laravel | Arie Visser
December 15, 2019 - One of the cool things of Laravel's validation rules, is that you can apply certain rules to different data types. When checking the minimum and maximum size of an array, you can use the min, max, between, and size rules, which you can also apply to strings and numerics.
Laracasts
laracasts.com › discuss › channels › laravel › how-to-get-array-count
how to get array count
public function pass_device_array(Request $request,$id, $enqid){ $man=explode(',', $id); $row = DB::table('device')->whereIn('id',$man)->pluck('id'); $row1 = DB::table('Enquiry')->where('id',$enqid)->first(); return view('pages.newinvoice', ['row' => $row, 'row1' => $row1]); } ... @Snapey Nothing to do with basic PHP. I was thinking that there would be a special Laravel function to get the count instead.
Laracasts
laracasts.com › discuss › channels › eloquent › wherein-array-length-limited
WhereIn array length limited?
The most popular Laravel and PHP programming forum.
Laracasts
laracasts.com › discuss › channels › laravel › show-array-count-in-blade
show array count in blade
The most popular Laravel and PHP programming forum.
Iterrorsolution
ww12.iterrorsolution.com › post › how-to-check-array-length-in-laravel.html
iterrorsolution.com
iterrorsolution.com · 2025 Copyright | All Rights Reserved. Privacy Policy
W3Schools
w3schools.com › php › func_array_sizeof.asp
PHP sizeof() Function
affected_rows autocommit change_user character_set_name close commit connect connect_errno connect_error data_seek debug dump_debug_info errno error error_list fetch_all fetch_array fetch_assoc fetch_field fetch_field_direct fetch_fields fetch_lengths fetch_object fetch_row field_count field_seek get_charset get_client_info get_client_stats get_client_version get_connection_stats get_host_info get_proto_info get_server_info get_server_version info init insert_id kill more_results multi_query next_result options ping poll prepare query real_connect real_escape_string real_query reap_async_query refresh rollback select_db set_charset set_local_infile_handler sqlstate ssl_set stat stmt_init thread_id thread_safe use_result warning_count PHP Network
Top answer 1 of 3
3
The thing is the way how you are sending the data to your backend. As it seems, your are grouping by attribute (an array of ids then an array of names and so on) instead than by "class" (an array of elements that contains all the attributes in it: id, name, ...).
So, you could solve this issue in two ways.
- Improving the way you are collecting the data in your frontend to send it to your back (recommended)
- Handle the data in the back as it is right now.
For the first way, there are several guides/tutorials that can help you with. So, let's proceed with the second one.
public function update(Request $request, $jobId)
{
/** This should output 2 */
$size = count(collect($request)->get('id'));
// Try: dd($size);
for ($i = 0; $i < $size; $i++)
{
$subJob = SubJob::Find($request->get('id')[$i]);
$subJob->job_id = $jobId;
$subJob->name = $request->get('name')[$i];
$subJob->size = $request->get('size')[$i];
$subJob->medium = $request->get('medium')[$i];
$subJob->feature = $request->get('feature')[$i];
$subJob->qty = $request->get('qty')[$i];
$subJob->price = $request->get('price')[$i];
$subJob->total = $request->get('qty')[$i] * $request->get('price')[$i];
$subJob->save();
}
}
2 of 3
1
Maybe try count($collection->items)
Laracasts
laracasts.com › discuss › channels › requests › add-array-size-check-to-validation
Add array size check to validation
The most popular Laravel and PHP programming forum.