Search query condition not working - Laravel 5.7
up vote
0
down vote
favorite
I have this in my view:
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12">
<form class="search-form search-form-basic" action="/candidates/index" method="post">
csrf_field()
<div class="form-row">
<div class="col-md-4 form-group">
<label for="search_email">First name:</label>
<input type="text" name="search_first_name" id="search_first_name" class="form-control" @if(isset(Session::get('inputs')['search_first_name'])) value=" Session::get('inputs')['search_first_name'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_last_name">Last name:</label>
<input type="text" name="search_last_name" id="search_last_name" class="form-control" @if(isset(Session::get('inputs')['search_last_name'])) value=" Session::get('inputs')['search_last_name'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_round_number">Round Number:</label>
<input type="text" name="search_round_number" id="search_round_number" class="form-control" placeholder="" @if(isset(Session::get('inputs')['search_round_number'])) value=" Session::get('inputs')['search_round_number'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_location">location:</label>
<input type="text" name="search_location" id="search_location" class="form-control"
@if(isset(Session::get('inputs')['search_location'])) value=" Session::get('inputs')['search_location'] " @endif>
</div>
<select name="options" class="col-md-4 form-group">
<option value="">--- Select From ---</option>
<option value="birth_date">Birth Date</option>
<option value="CV_grade_date">CV Grade Date</option>
<option value="source">Source</option>
<option value="recommendation">Recommended</option>
<option value="created_at">Applied</option>
</select>
<div class="col-md-4 form-group">
<label for="search_from_date">From:</label>
<input type="date" name="search_from_date" id="search_from_date" class="form-control"
@if(isset(Session::get('inputs')['search_from_date'])) value=" Session::get('inputs')['search_from_date'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_to_date">To:</label>
<input type="date" name="search_to_date" id="search_to_date" class="form-control"
@if(isset(Session::get('inputs')['search_to_date'])) value=" Session::get('inputs')['search_to_date'] " @endif>
</div>
</div>
<div class="form-row">
<div class="col-md-12 col-lg-12">
<button type="submit" class="btn btn-custom"><i class="fa fa-search" aria-hidden="true"></i>Search</button>
<a href="/users" class="btn btn-custom"><i class="fa fa-times-circle" aria-hidden="true"></i>Clear</a>
</div>
</div>
</form>
</div>
My controller:
public function index(Request $request) {
if($request->isMethod('post'))else
Session::forget('inputs');
$candidate = Candidate::orderBy('first_name', 'asc')
->orderBy('last_name', 'asc')
->get();
return view('/candidates/index', [
'candidate' => $candidate
]);
When I select "source" as one of the options, and enter from-to dates, I'm receiving this error:
Column not found: 1054 Unknown column '1' in 'where clause' (SQL: select * from
candidates
where1
is null andcreated_at
between 2015-8-8 and 2019-1-1 andsource
between 2015-8-8 and 2019-1-1 order byfirst_name
asc,last_name
asc)
However, dd($recOrSource) is returning correct value; I don't see where this "1" is coming from, and why this part is run
->when($options, function ($query) use ($options,$search_from_date,$search_to_date )
return $query->whereBetween($options, array($search_from_date, $search_to_date));
)
when I have
if($options == 'recommendation' || $options == 'source')
$recOrSource = Input::get('options');
$options == null;
php laravel
add a comment |
up vote
0
down vote
favorite
I have this in my view:
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12">
<form class="search-form search-form-basic" action="/candidates/index" method="post">
csrf_field()
<div class="form-row">
<div class="col-md-4 form-group">
<label for="search_email">First name:</label>
<input type="text" name="search_first_name" id="search_first_name" class="form-control" @if(isset(Session::get('inputs')['search_first_name'])) value=" Session::get('inputs')['search_first_name'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_last_name">Last name:</label>
<input type="text" name="search_last_name" id="search_last_name" class="form-control" @if(isset(Session::get('inputs')['search_last_name'])) value=" Session::get('inputs')['search_last_name'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_round_number">Round Number:</label>
<input type="text" name="search_round_number" id="search_round_number" class="form-control" placeholder="" @if(isset(Session::get('inputs')['search_round_number'])) value=" Session::get('inputs')['search_round_number'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_location">location:</label>
<input type="text" name="search_location" id="search_location" class="form-control"
@if(isset(Session::get('inputs')['search_location'])) value=" Session::get('inputs')['search_location'] " @endif>
</div>
<select name="options" class="col-md-4 form-group">
<option value="">--- Select From ---</option>
<option value="birth_date">Birth Date</option>
<option value="CV_grade_date">CV Grade Date</option>
<option value="source">Source</option>
<option value="recommendation">Recommended</option>
<option value="created_at">Applied</option>
</select>
<div class="col-md-4 form-group">
<label for="search_from_date">From:</label>
<input type="date" name="search_from_date" id="search_from_date" class="form-control"
@if(isset(Session::get('inputs')['search_from_date'])) value=" Session::get('inputs')['search_from_date'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_to_date">To:</label>
<input type="date" name="search_to_date" id="search_to_date" class="form-control"
@if(isset(Session::get('inputs')['search_to_date'])) value=" Session::get('inputs')['search_to_date'] " @endif>
</div>
</div>
<div class="form-row">
<div class="col-md-12 col-lg-12">
<button type="submit" class="btn btn-custom"><i class="fa fa-search" aria-hidden="true"></i>Search</button>
<a href="/users" class="btn btn-custom"><i class="fa fa-times-circle" aria-hidden="true"></i>Clear</a>
</div>
</div>
</form>
</div>
My controller:
public function index(Request $request) {
if($request->isMethod('post'))else
Session::forget('inputs');
$candidate = Candidate::orderBy('first_name', 'asc')
->orderBy('last_name', 'asc')
->get();
return view('/candidates/index', [
'candidate' => $candidate
]);
When I select "source" as one of the options, and enter from-to dates, I'm receiving this error:
Column not found: 1054 Unknown column '1' in 'where clause' (SQL: select * from
candidates
where1
is null andcreated_at
between 2015-8-8 and 2019-1-1 andsource
between 2015-8-8 and 2019-1-1 order byfirst_name
asc,last_name
asc)
However, dd($recOrSource) is returning correct value; I don't see where this "1" is coming from, and why this part is run
->when($options, function ($query) use ($options,$search_from_date,$search_to_date )
return $query->whereBetween($options, array($search_from_date, $search_to_date));
)
when I have
if($options == 'recommendation' || $options == 'source')
$recOrSource = Input::get('options');
$options == null;
php laravel
I think the problem should be with this part: $query->where(!empty($recOrSource)). where are the other args and what do you want to fetch with this part of code?
– Fatemeh Majd
Nov 10 at 13:57
I agree, but couldn't figure it out. I'm trying to get either 'source' or 'recommendation' as a value of that variable, so that I can filter for candidates that have != null in one of those 2 columns, by using ->when($recOrSource, function ($query) use ($recOrSource,$search_from_date,$search_to_date) return $query->where(!empty($recOrSource))->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 14:14
you should use something like: where(function($query)if ($firstOne)$query->whereNotNull('firstVar'); else $query->whereNotNull('secondVar'););
– Fatemeh Majd
Nov 10 at 14:45
This is working, think the only issued is timestamp format of 'created_at'. I applied something similar for 'source' column, and now it;s working: ->when($rec, function ($query) use ($rec,$search_from_date,$search_to_date) return $query->where('recommendation', ('1')) ->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 18:30
and this: if($options == 'recommendation') $rec = Input::get('options'); $options == null; if($options == 'source') $source = Input::get('options'); $options == null;
– Nick
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have this in my view:
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12">
<form class="search-form search-form-basic" action="/candidates/index" method="post">
csrf_field()
<div class="form-row">
<div class="col-md-4 form-group">
<label for="search_email">First name:</label>
<input type="text" name="search_first_name" id="search_first_name" class="form-control" @if(isset(Session::get('inputs')['search_first_name'])) value=" Session::get('inputs')['search_first_name'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_last_name">Last name:</label>
<input type="text" name="search_last_name" id="search_last_name" class="form-control" @if(isset(Session::get('inputs')['search_last_name'])) value=" Session::get('inputs')['search_last_name'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_round_number">Round Number:</label>
<input type="text" name="search_round_number" id="search_round_number" class="form-control" placeholder="" @if(isset(Session::get('inputs')['search_round_number'])) value=" Session::get('inputs')['search_round_number'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_location">location:</label>
<input type="text" name="search_location" id="search_location" class="form-control"
@if(isset(Session::get('inputs')['search_location'])) value=" Session::get('inputs')['search_location'] " @endif>
</div>
<select name="options" class="col-md-4 form-group">
<option value="">--- Select From ---</option>
<option value="birth_date">Birth Date</option>
<option value="CV_grade_date">CV Grade Date</option>
<option value="source">Source</option>
<option value="recommendation">Recommended</option>
<option value="created_at">Applied</option>
</select>
<div class="col-md-4 form-group">
<label for="search_from_date">From:</label>
<input type="date" name="search_from_date" id="search_from_date" class="form-control"
@if(isset(Session::get('inputs')['search_from_date'])) value=" Session::get('inputs')['search_from_date'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_to_date">To:</label>
<input type="date" name="search_to_date" id="search_to_date" class="form-control"
@if(isset(Session::get('inputs')['search_to_date'])) value=" Session::get('inputs')['search_to_date'] " @endif>
</div>
</div>
<div class="form-row">
<div class="col-md-12 col-lg-12">
<button type="submit" class="btn btn-custom"><i class="fa fa-search" aria-hidden="true"></i>Search</button>
<a href="/users" class="btn btn-custom"><i class="fa fa-times-circle" aria-hidden="true"></i>Clear</a>
</div>
</div>
</form>
</div>
My controller:
public function index(Request $request) {
if($request->isMethod('post'))else
Session::forget('inputs');
$candidate = Candidate::orderBy('first_name', 'asc')
->orderBy('last_name', 'asc')
->get();
return view('/candidates/index', [
'candidate' => $candidate
]);
When I select "source" as one of the options, and enter from-to dates, I'm receiving this error:
Column not found: 1054 Unknown column '1' in 'where clause' (SQL: select * from
candidates
where1
is null andcreated_at
between 2015-8-8 and 2019-1-1 andsource
between 2015-8-8 and 2019-1-1 order byfirst_name
asc,last_name
asc)
However, dd($recOrSource) is returning correct value; I don't see where this "1" is coming from, and why this part is run
->when($options, function ($query) use ($options,$search_from_date,$search_to_date )
return $query->whereBetween($options, array($search_from_date, $search_to_date));
)
when I have
if($options == 'recommendation' || $options == 'source')
$recOrSource = Input::get('options');
$options == null;
php laravel
I have this in my view:
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12">
<form class="search-form search-form-basic" action="/candidates/index" method="post">
csrf_field()
<div class="form-row">
<div class="col-md-4 form-group">
<label for="search_email">First name:</label>
<input type="text" name="search_first_name" id="search_first_name" class="form-control" @if(isset(Session::get('inputs')['search_first_name'])) value=" Session::get('inputs')['search_first_name'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_last_name">Last name:</label>
<input type="text" name="search_last_name" id="search_last_name" class="form-control" @if(isset(Session::get('inputs')['search_last_name'])) value=" Session::get('inputs')['search_last_name'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_round_number">Round Number:</label>
<input type="text" name="search_round_number" id="search_round_number" class="form-control" placeholder="" @if(isset(Session::get('inputs')['search_round_number'])) value=" Session::get('inputs')['search_round_number'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_location">location:</label>
<input type="text" name="search_location" id="search_location" class="form-control"
@if(isset(Session::get('inputs')['search_location'])) value=" Session::get('inputs')['search_location'] " @endif>
</div>
<select name="options" class="col-md-4 form-group">
<option value="">--- Select From ---</option>
<option value="birth_date">Birth Date</option>
<option value="CV_grade_date">CV Grade Date</option>
<option value="source">Source</option>
<option value="recommendation">Recommended</option>
<option value="created_at">Applied</option>
</select>
<div class="col-md-4 form-group">
<label for="search_from_date">From:</label>
<input type="date" name="search_from_date" id="search_from_date" class="form-control"
@if(isset(Session::get('inputs')['search_from_date'])) value=" Session::get('inputs')['search_from_date'] " @endif>
</div>
<div class="col-md-4 form-group">
<label for="search_to_date">To:</label>
<input type="date" name="search_to_date" id="search_to_date" class="form-control"
@if(isset(Session::get('inputs')['search_to_date'])) value=" Session::get('inputs')['search_to_date'] " @endif>
</div>
</div>
<div class="form-row">
<div class="col-md-12 col-lg-12">
<button type="submit" class="btn btn-custom"><i class="fa fa-search" aria-hidden="true"></i>Search</button>
<a href="/users" class="btn btn-custom"><i class="fa fa-times-circle" aria-hidden="true"></i>Clear</a>
</div>
</div>
</form>
</div>
My controller:
public function index(Request $request) {
if($request->isMethod('post'))else
Session::forget('inputs');
$candidate = Candidate::orderBy('first_name', 'asc')
->orderBy('last_name', 'asc')
->get();
return view('/candidates/index', [
'candidate' => $candidate
]);
When I select "source" as one of the options, and enter from-to dates, I'm receiving this error:
Column not found: 1054 Unknown column '1' in 'where clause' (SQL: select * from
candidates
where1
is null andcreated_at
between 2015-8-8 and 2019-1-1 andsource
between 2015-8-8 and 2019-1-1 order byfirst_name
asc,last_name
asc)
However, dd($recOrSource) is returning correct value; I don't see where this "1" is coming from, and why this part is run
->when($options, function ($query) use ($options,$search_from_date,$search_to_date )
return $query->whereBetween($options, array($search_from_date, $search_to_date));
)
when I have
if($options == 'recommendation' || $options == 'source')
$recOrSource = Input::get('options');
$options == null;
php laravel
php laravel
asked Nov 10 at 13:36
Nick
124
124
I think the problem should be with this part: $query->where(!empty($recOrSource)). where are the other args and what do you want to fetch with this part of code?
– Fatemeh Majd
Nov 10 at 13:57
I agree, but couldn't figure it out. I'm trying to get either 'source' or 'recommendation' as a value of that variable, so that I can filter for candidates that have != null in one of those 2 columns, by using ->when($recOrSource, function ($query) use ($recOrSource,$search_from_date,$search_to_date) return $query->where(!empty($recOrSource))->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 14:14
you should use something like: where(function($query)if ($firstOne)$query->whereNotNull('firstVar'); else $query->whereNotNull('secondVar'););
– Fatemeh Majd
Nov 10 at 14:45
This is working, think the only issued is timestamp format of 'created_at'. I applied something similar for 'source' column, and now it;s working: ->when($rec, function ($query) use ($rec,$search_from_date,$search_to_date) return $query->where('recommendation', ('1')) ->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 18:30
and this: if($options == 'recommendation') $rec = Input::get('options'); $options == null; if($options == 'source') $source = Input::get('options'); $options == null;
– Nick
yesterday
add a comment |
I think the problem should be with this part: $query->where(!empty($recOrSource)). where are the other args and what do you want to fetch with this part of code?
– Fatemeh Majd
Nov 10 at 13:57
I agree, but couldn't figure it out. I'm trying to get either 'source' or 'recommendation' as a value of that variable, so that I can filter for candidates that have != null in one of those 2 columns, by using ->when($recOrSource, function ($query) use ($recOrSource,$search_from_date,$search_to_date) return $query->where(!empty($recOrSource))->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 14:14
you should use something like: where(function($query)if ($firstOne)$query->whereNotNull('firstVar'); else $query->whereNotNull('secondVar'););
– Fatemeh Majd
Nov 10 at 14:45
This is working, think the only issued is timestamp format of 'created_at'. I applied something similar for 'source' column, and now it;s working: ->when($rec, function ($query) use ($rec,$search_from_date,$search_to_date) return $query->where('recommendation', ('1')) ->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 18:30
and this: if($options == 'recommendation') $rec = Input::get('options'); $options == null; if($options == 'source') $source = Input::get('options'); $options == null;
– Nick
yesterday
I think the problem should be with this part: $query->where(!empty($recOrSource)). where are the other args and what do you want to fetch with this part of code?
– Fatemeh Majd
Nov 10 at 13:57
I think the problem should be with this part: $query->where(!empty($recOrSource)). where are the other args and what do you want to fetch with this part of code?
– Fatemeh Majd
Nov 10 at 13:57
I agree, but couldn't figure it out. I'm trying to get either 'source' or 'recommendation' as a value of that variable, so that I can filter for candidates that have != null in one of those 2 columns, by using ->when($recOrSource, function ($query) use ($recOrSource,$search_from_date,$search_to_date) return $query->where(!empty($recOrSource))->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 14:14
I agree, but couldn't figure it out. I'm trying to get either 'source' or 'recommendation' as a value of that variable, so that I can filter for candidates that have != null in one of those 2 columns, by using ->when($recOrSource, function ($query) use ($recOrSource,$search_from_date,$search_to_date) return $query->where(!empty($recOrSource))->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 14:14
you should use something like: where(function($query)if ($firstOne)$query->whereNotNull('firstVar'); else $query->whereNotNull('secondVar'););
– Fatemeh Majd
Nov 10 at 14:45
you should use something like: where(function($query)if ($firstOne)$query->whereNotNull('firstVar'); else $query->whereNotNull('secondVar'););
– Fatemeh Majd
Nov 10 at 14:45
This is working, think the only issued is timestamp format of 'created_at'. I applied something similar for 'source' column, and now it;s working: ->when($rec, function ($query) use ($rec,$search_from_date,$search_to_date) return $query->where('recommendation', ('1')) ->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 18:30
This is working, think the only issued is timestamp format of 'created_at'. I applied something similar for 'source' column, and now it;s working: ->when($rec, function ($query) use ($rec,$search_from_date,$search_to_date) return $query->where('recommendation', ('1')) ->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 18:30
and this: if($options == 'recommendation') $rec = Input::get('options'); $options == null; if($options == 'source') $source = Input::get('options'); $options == null;
– Nick
yesterday
and this: if($options == 'recommendation') $rec = Input::get('options'); $options == null; if($options == 'source') $source = Input::get('options'); $options == null;
– Nick
yesterday
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239515%2fsearch-query-condition-not-working-laravel-5-7%23new-answer', 'question_page');
);
Post as a guest
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
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
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
I think the problem should be with this part: $query->where(!empty($recOrSource)). where are the other args and what do you want to fetch with this part of code?
– Fatemeh Majd
Nov 10 at 13:57
I agree, but couldn't figure it out. I'm trying to get either 'source' or 'recommendation' as a value of that variable, so that I can filter for candidates that have != null in one of those 2 columns, by using ->when($recOrSource, function ($query) use ($recOrSource,$search_from_date,$search_to_date) return $query->where(!empty($recOrSource))->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 14:14
you should use something like: where(function($query)if ($firstOne)$query->whereNotNull('firstVar'); else $query->whereNotNull('secondVar'););
– Fatemeh Majd
Nov 10 at 14:45
This is working, think the only issued is timestamp format of 'created_at'. I applied something similar for 'source' column, and now it;s working: ->when($rec, function ($query) use ($rec,$search_from_date,$search_to_date) return $query->where('recommendation', ('1')) ->whereBetween('created_at', array($search_from_date, $search_to_date)); )
– Nick
Nov 10 at 18:30
and this: if($options == 'recommendation') $rec = Input::get('options'); $options == null; if($options == 'source') $source = Input::get('options'); $options == null;
– Nick
yesterday