Laravel count issue
up vote
0
down vote
favorite
I am trying to search by check-boxes and conditions but i get this error in return:
count(): Parameter must be an array or an object that implements Countable
Logic
- I can select 1 or more options
- In back-end check what kind of options has selected
- Depend of the kind return results
Code
controller
public function advancedsearch(Request $request) {
$options = Specification::whereHas('subspecifications')->with(['subspecifications' => function($query) {
$query->status('Active');
}])->get();
$brands = Brand::all();
$brandss = Input::has('brands') ? Input::get('brands') : ;
$suboption = Input::has('suboptions') ? (int)Input::get('suboptions') : ;
$min_price = Input::has('min_price') ? (int)Input::get('min_price') : null;
$max_price = Input::has('max_price') ? (int)Input::get('max_price') : null;
//codes
if(count($request['suboptions'])){
$products = DB::table('products')
->join('product_subspecification', function ($join) {
$suboption = Input::has('suboptions') ? Input::get('suboptions') : ;
$join->on('products.id', '=', 'product_subspecification.product_id')
->where('product_subspecification.subspecification_id', '=', $suboption);
})
->paginate(12);
}
elseif(count($request['brands'])){
$products = DB::table('products')
->whereIn('products.brand_id', $brandss)
->paginate(12);
}
elseif(count($request['min_price']) && count($request['max_price'])){
$products = DB::table('products')
->whereBetween('price', [$min_price, $max_price])
->paginate(12);
}
return view('front.advancesearch', compact('products', 'brands', 'options'));
}
Summary of code above
I am getting all brands from database and check if only 1 brand has selected or several
$brands = Brand::all();
$brandss = Input::has('brands') ? Input::get('brands') : ;
Then I check if any brand has selected in general or no by count
and returning results
elseif(count($request['brands'])){
$products = DB::table('products')
->whereIn('products.brand_id', $brandss)
->paginate(12);
}
but I get error I share above.
Any idea?
Update
how my html look likes
how the result **dd** look like
array:4 [▼
"_token" => "Wqs9yzd5qwGtbv01asbCzsISeVQxHsCoWVQM1ifO"
"brands" => array:1 [▼
0 => "3"
]
"min_price" => null
"max_price" => null
]
Blade
<div class="checkbox">
@foreach($option->subspecifications as $suboption)
@if($option->title == 'Brand')
<label for="brands">
<input name="brands" type="checkbox" value="{{$suboption->id}}">
{{ucfirst($suboption->title)}}
</label>
@else
<label for="suboptions">
<input name="suboptions" type="checkbox" value="{{$suboption->id}}">
{{ucfirst($suboption->title)}}
</label>
@endif
@endforeach
</div>
php laravel count
|
show 4 more comments
up vote
0
down vote
favorite
I am trying to search by check-boxes and conditions but i get this error in return:
count(): Parameter must be an array or an object that implements Countable
Logic
- I can select 1 or more options
- In back-end check what kind of options has selected
- Depend of the kind return results
Code
controller
public function advancedsearch(Request $request) {
$options = Specification::whereHas('subspecifications')->with(['subspecifications' => function($query) {
$query->status('Active');
}])->get();
$brands = Brand::all();
$brandss = Input::has('brands') ? Input::get('brands') : ;
$suboption = Input::has('suboptions') ? (int)Input::get('suboptions') : ;
$min_price = Input::has('min_price') ? (int)Input::get('min_price') : null;
$max_price = Input::has('max_price') ? (int)Input::get('max_price') : null;
//codes
if(count($request['suboptions'])){
$products = DB::table('products')
->join('product_subspecification', function ($join) {
$suboption = Input::has('suboptions') ? Input::get('suboptions') : ;
$join->on('products.id', '=', 'product_subspecification.product_id')
->where('product_subspecification.subspecification_id', '=', $suboption);
})
->paginate(12);
}
elseif(count($request['brands'])){
$products = DB::table('products')
->whereIn('products.brand_id', $brandss)
->paginate(12);
}
elseif(count($request['min_price']) && count($request['max_price'])){
$products = DB::table('products')
->whereBetween('price', [$min_price, $max_price])
->paginate(12);
}
return view('front.advancesearch', compact('products', 'brands', 'options'));
}
Summary of code above
I am getting all brands from database and check if only 1 brand has selected or several
$brands = Brand::all();
$brandss = Input::has('brands') ? Input::get('brands') : ;
Then I check if any brand has selected in general or no by count
and returning results
elseif(count($request['brands'])){
$products = DB::table('products')
->whereIn('products.brand_id', $brandss)
->paginate(12);
}
but I get error I share above.
Any idea?
Update
how my html look likes
how the result **dd** look like
array:4 [▼
"_token" => "Wqs9yzd5qwGtbv01asbCzsISeVQxHsCoWVQM1ifO"
"brands" => array:1 [▼
0 => "3"
]
"min_price" => null
"max_price" => null
]
Blade
<div class="checkbox">
@foreach($option->subspecifications as $suboption)
@if($option->title == 'Brand')
<label for="brands">
<input name="brands" type="checkbox" value="{{$suboption->id}}">
{{ucfirst($suboption->title)}}
</label>
@else
<label for="suboptions">
<input name="suboptions" type="checkbox" value="{{$suboption->id}}">
{{ucfirst($suboption->title)}}
</label>
@endif
@endforeach
</div>
php laravel count
1
What's your HTML look like? Is your input namedbrands
so that it comes back as an array?
– miken32
Nov 9 at 5:05
@miken32 this is how it looks like ibb.co/gKDhvA
– mafortis
Nov 9 at 5:11
Edit your question to include the relevant HTML. I'm not going to click on that link.
– miken32
Nov 9 at 5:12
@miken32 updated! ......
– mafortis
Nov 9 at 5:15
1
laravel.com/docs/5.6/requests#retrieving-input
– miken32
Nov 9 at 5:32
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to search by check-boxes and conditions but i get this error in return:
count(): Parameter must be an array or an object that implements Countable
Logic
- I can select 1 or more options
- In back-end check what kind of options has selected
- Depend of the kind return results
Code
controller
public function advancedsearch(Request $request) {
$options = Specification::whereHas('subspecifications')->with(['subspecifications' => function($query) {
$query->status('Active');
}])->get();
$brands = Brand::all();
$brandss = Input::has('brands') ? Input::get('brands') : ;
$suboption = Input::has('suboptions') ? (int)Input::get('suboptions') : ;
$min_price = Input::has('min_price') ? (int)Input::get('min_price') : null;
$max_price = Input::has('max_price') ? (int)Input::get('max_price') : null;
//codes
if(count($request['suboptions'])){
$products = DB::table('products')
->join('product_subspecification', function ($join) {
$suboption = Input::has('suboptions') ? Input::get('suboptions') : ;
$join->on('products.id', '=', 'product_subspecification.product_id')
->where('product_subspecification.subspecification_id', '=', $suboption);
})
->paginate(12);
}
elseif(count($request['brands'])){
$products = DB::table('products')
->whereIn('products.brand_id', $brandss)
->paginate(12);
}
elseif(count($request['min_price']) && count($request['max_price'])){
$products = DB::table('products')
->whereBetween('price', [$min_price, $max_price])
->paginate(12);
}
return view('front.advancesearch', compact('products', 'brands', 'options'));
}
Summary of code above
I am getting all brands from database and check if only 1 brand has selected or several
$brands = Brand::all();
$brandss = Input::has('brands') ? Input::get('brands') : ;
Then I check if any brand has selected in general or no by count
and returning results
elseif(count($request['brands'])){
$products = DB::table('products')
->whereIn('products.brand_id', $brandss)
->paginate(12);
}
but I get error I share above.
Any idea?
Update
how my html look likes
how the result **dd** look like
array:4 [▼
"_token" => "Wqs9yzd5qwGtbv01asbCzsISeVQxHsCoWVQM1ifO"
"brands" => array:1 [▼
0 => "3"
]
"min_price" => null
"max_price" => null
]
Blade
<div class="checkbox">
@foreach($option->subspecifications as $suboption)
@if($option->title == 'Brand')
<label for="brands">
<input name="brands" type="checkbox" value="{{$suboption->id}}">
{{ucfirst($suboption->title)}}
</label>
@else
<label for="suboptions">
<input name="suboptions" type="checkbox" value="{{$suboption->id}}">
{{ucfirst($suboption->title)}}
</label>
@endif
@endforeach
</div>
php laravel count
I am trying to search by check-boxes and conditions but i get this error in return:
count(): Parameter must be an array or an object that implements Countable
Logic
- I can select 1 or more options
- In back-end check what kind of options has selected
- Depend of the kind return results
Code
controller
public function advancedsearch(Request $request) {
$options = Specification::whereHas('subspecifications')->with(['subspecifications' => function($query) {
$query->status('Active');
}])->get();
$brands = Brand::all();
$brandss = Input::has('brands') ? Input::get('brands') : ;
$suboption = Input::has('suboptions') ? (int)Input::get('suboptions') : ;
$min_price = Input::has('min_price') ? (int)Input::get('min_price') : null;
$max_price = Input::has('max_price') ? (int)Input::get('max_price') : null;
//codes
if(count($request['suboptions'])){
$products = DB::table('products')
->join('product_subspecification', function ($join) {
$suboption = Input::has('suboptions') ? Input::get('suboptions') : ;
$join->on('products.id', '=', 'product_subspecification.product_id')
->where('product_subspecification.subspecification_id', '=', $suboption);
})
->paginate(12);
}
elseif(count($request['brands'])){
$products = DB::table('products')
->whereIn('products.brand_id', $brandss)
->paginate(12);
}
elseif(count($request['min_price']) && count($request['max_price'])){
$products = DB::table('products')
->whereBetween('price', [$min_price, $max_price])
->paginate(12);
}
return view('front.advancesearch', compact('products', 'brands', 'options'));
}
Summary of code above
I am getting all brands from database and check if only 1 brand has selected or several
$brands = Brand::all();
$brandss = Input::has('brands') ? Input::get('brands') : ;
Then I check if any brand has selected in general or no by count
and returning results
elseif(count($request['brands'])){
$products = DB::table('products')
->whereIn('products.brand_id', $brandss)
->paginate(12);
}
but I get error I share above.
Any idea?
Update
how my html look likes
how the result **dd** look like
array:4 [▼
"_token" => "Wqs9yzd5qwGtbv01asbCzsISeVQxHsCoWVQM1ifO"
"brands" => array:1 [▼
0 => "3"
]
"min_price" => null
"max_price" => null
]
Blade
<div class="checkbox">
@foreach($option->subspecifications as $suboption)
@if($option->title == 'Brand')
<label for="brands">
<input name="brands" type="checkbox" value="{{$suboption->id}}">
{{ucfirst($suboption->title)}}
</label>
@else
<label for="suboptions">
<input name="suboptions" type="checkbox" value="{{$suboption->id}}">
{{ucfirst($suboption->title)}}
</label>
@endif
@endforeach
</div>
php laravel count
php laravel count
edited Nov 9 at 5:12
asked Nov 9 at 4:53
mafortis
930634
930634
1
What's your HTML look like? Is your input namedbrands
so that it comes back as an array?
– miken32
Nov 9 at 5:05
@miken32 this is how it looks like ibb.co/gKDhvA
– mafortis
Nov 9 at 5:11
Edit your question to include the relevant HTML. I'm not going to click on that link.
– miken32
Nov 9 at 5:12
@miken32 updated! ......
– mafortis
Nov 9 at 5:15
1
laravel.com/docs/5.6/requests#retrieving-input
– miken32
Nov 9 at 5:32
|
show 4 more comments
1
What's your HTML look like? Is your input namedbrands
so that it comes back as an array?
– miken32
Nov 9 at 5:05
@miken32 this is how it looks like ibb.co/gKDhvA
– mafortis
Nov 9 at 5:11
Edit your question to include the relevant HTML. I'm not going to click on that link.
– miken32
Nov 9 at 5:12
@miken32 updated! ......
– mafortis
Nov 9 at 5:15
1
laravel.com/docs/5.6/requests#retrieving-input
– miken32
Nov 9 at 5:32
1
1
What's your HTML look like? Is your input named
brands
so that it comes back as an array?– miken32
Nov 9 at 5:05
What's your HTML look like? Is your input named
brands
so that it comes back as an array?– miken32
Nov 9 at 5:05
@miken32 this is how it looks like ibb.co/gKDhvA
– mafortis
Nov 9 at 5:11
@miken32 this is how it looks like ibb.co/gKDhvA
– mafortis
Nov 9 at 5:11
Edit your question to include the relevant HTML. I'm not going to click on that link.
– miken32
Nov 9 at 5:12
Edit your question to include the relevant HTML. I'm not going to click on that link.
– miken32
Nov 9 at 5:12
@miken32 updated! ......
– mafortis
Nov 9 at 5:15
@miken32 updated! ......
– mafortis
Nov 9 at 5:15
1
1
laravel.com/docs/5.6/requests#retrieving-input
– miken32
Nov 9 at 5:32
laravel.com/docs/5.6/requests#retrieving-input
– miken32
Nov 9 at 5:32
|
show 4 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Solved
Changed count with has solved the issue
elseif($request->has['brands']){
PS: Based on 3 different functions that I have, which returns data of my search I have mixed results but it doesn't related to this
question.count
error solved so I'll mark it as solved.
Thanks to miken32
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Solved
Changed count with has solved the issue
elseif($request->has['brands']){
PS: Based on 3 different functions that I have, which returns data of my search I have mixed results but it doesn't related to this
question.count
error solved so I'll mark it as solved.
Thanks to miken32
add a comment |
up vote
0
down vote
accepted
Solved
Changed count with has solved the issue
elseif($request->has['brands']){
PS: Based on 3 different functions that I have, which returns data of my search I have mixed results but it doesn't related to this
question.count
error solved so I'll mark it as solved.
Thanks to miken32
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Solved
Changed count with has solved the issue
elseif($request->has['brands']){
PS: Based on 3 different functions that I have, which returns data of my search I have mixed results but it doesn't related to this
question.count
error solved so I'll mark it as solved.
Thanks to miken32
Solved
Changed count with has solved the issue
elseif($request->has['brands']){
PS: Based on 3 different functions that I have, which returns data of my search I have mixed results but it doesn't related to this
question.count
error solved so I'll mark it as solved.
Thanks to miken32
answered Nov 9 at 5:46
mafortis
930634
930634
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53220062%2flaravel-count-issue%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What's your HTML look like? Is your input named
brands
so that it comes back as an array?– miken32
Nov 9 at 5:05
@miken32 this is how it looks like ibb.co/gKDhvA
– mafortis
Nov 9 at 5:11
Edit your question to include the relevant HTML. I'm not going to click on that link.
– miken32
Nov 9 at 5:12
@miken32 updated! ......
– mafortis
Nov 9 at 5:15
1
laravel.com/docs/5.6/requests#retrieving-input
– miken32
Nov 9 at 5:32