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
How to use data of a JSON object output from controller in blade file?
To do it in the controller first you should decode the data using json_decode to an associative array, then iterate the data property. It should look like this: $json = PageResult::make($result->answers); $decoded = json_decode($json, true); // true to convert to associative array $data = $decoded['data'] foreach ($data as $array) { $section=$array['section'] ... } Finally, store that data in an array and use it as you will. Another solution is to pass the decoded object in the blade view and use it there. Something like this: return view('my-view, ['data' => json_decode($json, true)] Hope this helps More on reddit.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.
DevOps Consulting
devopsconsulting.in › blog › array-length-validation-in-laravel
Array Length Validation in Laravel - DevOps Consulting
July 25, 2023 - In Laravel, we occasionally need ... maximum length of an array. A minimum of two array values must be added by the user. Laravel therefore offers default array validation rules. array, min, max, between, and size rules can all be used to apply to an array. ... When you have to validate that an array contains at least three, but not more than ten users, you can apply the between rule: ... <?php namespace App\Http\Controllers; use ...
Osvod
osvod.com.ua › putting-two › array-length-in-laravel-controller
array length in laravel controller
July 31, 2023 - Find centralized, trusted content and collaborate around the technologies you use most. As mentioned above, the collect helper returns a new Illuminate\Support\Collection instance for the given array. Example 1 Str::length method in laravel Controller stubs may be customized using stub publishing.
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
$idCount = count($array); Like Reply · Snapey · 7 years ago · Level 122 · ReplyReport Spam · 3 year old thread · BASIC PHP SKILLS REQUIRED · Like Reply · 1 like · aurelianspodarec · 4 years ago · Level 7 · ReplyReport Spam · @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)