我正在使用搜索功能。那是laravel中的代码:
{{ Form::select('career_solution_type',
['' => 'Select ',
'0' => 'On request',
'1' => 'On offer'],null) }}
现在,我正在尝试将其更改为具有相同值的切换按钮和用于更改值的javascript。这是视图中的新代码:
<input onclick="change2()" type="checkbox" name="career_solution_type" value="1" id="asap" checked="checked">
<span class="sliderCr round select" id="my-header" onclick="myFunction3()" ></span>
和我的JavaScript
function change2() // no ';' here
{
var elem = document.getElementById("asap");
if (elem.value === "1") {
elem.value = "0";
} else if (elem.value === "0") {
elem.value = "1";
}
}
我的控制器
public function searchCareerSolutions1($search = null,$career_solution_type =null,$topic_category_id = null,$topic_subcategory_id = null,$location = null,$city = null,$radius = null,$employment_type = null,$estimated_salary = null,$username = null,$role = null,$name = null,$contact_level = null,$language_skills = null,$page = null)
{
// if($page == "")
// {
// return redirect('find-user/'.Input::get('role').'/'.Input::get('search').'/1');
// }
// return $role;
$data = $this->data;
$data['title'] = "Career solutions";
$data['breadcrumbs'] = "Search for career solutions";
$page = Input::get('page');
if(!$page)
{
$page = 1;
}
$perPage = 12;
$offset = ($page * $perPage) - $perPage;
// $career_solution = CareerSolution::all();
// echo "<pre>";
$data['parent_category'] = \App\Category::where('parent_id','=',0)->get();
$data['child_category'] = \App\Category::where('parent_id','!=',0)->get();
$data['countryList'] = [''=>'Country'] + \App\Country::lists('country','code')->toArray();
// DB::enableQueryLog();
$career_solution = CareerSolution::with('user.role','user.privancy_setting','category','sub_category','country');
$career_solution = $career_solution->where(function ($query) {
$query->where('expires_at','>=', date('Y-m-d'))
->orWhere('expires_at', '=', '0000-00-00');
});
$data['search'] = Input::get('search');
$data['career_solution_type'] = Input::get('career_solution_type');
$data['topic_category_id'] = Input::get('topic_category_id');
$data['topic_subcategory_id'] = Input::get('topic_subcategory_id');
$data['location'] = Input::get('location');
$data['city'] = Input::get('career_city');
$data['radius'] = Input::get('radius');
$data['employment_type'] = Input::get('employment_type');
$data['estimated_salary'] = Input::get('estimated_salary');
$username = Input::get('username');
$data['role'] = Input::get('role');
$data['name'] = Input::get('name');
$data['contact_level'] = Input::get('contact_level');
$data['language_skills'] = Input::get('language_skills');
if(!empty($data['search']))
{
$career_solution = $career_solution->where('subject', 'LIKE', '%'.$data['search'].'%');
}
// return $data['career_solution_type'];
if($data['career_solution_type'] != "")
{
// return $data['career_solution_type'];
$career_solution = $career_solution->where('on_offer', '=',$data['career_solution_type']);
$data['career_solution_type'] = $data['career_solution_type'];
}
if(!empty($data['topic_category_id']))
{
// return $data['topic_category_id'];
$category_id = \App\Category::where('category_url', '=' ,$data['topic_category_id'])->first(['id']);
$career_solution = $career_solution->where('topic_category_id', '=',$category_id->id);
// return $career_solution->get();
}
if(!empty($data['topic_subcategory_id']))
{
// return $data['topic_subcategory_id'];
$career_solution = $career_solution->where('topic_subcategory_id', '=',$data['topic_subcategory_id']);
$data['topic_subcategory'] = \App\CareerSolutionCategory::findOrfail($data['topic_subcategory_id']);
// // $data['topic_subcategory_id'] = $topic_subcategory_id[1];
// http://localhost/sonali/worksticker/public/search-career-solutions?career_solution_type=&search=&topic_category_id=career-planning&topic_subcategory_id=753&location=&career_city=&employment_type=&estimated_salary=
}
if(!empty($data['location']))
{
$career_solution = $career_solution->where('location', '=',$data['location']);
$data['country'] = \App\Country::where('id', '=' ,$data['location'])->first();
}
if(!empty($data['city']))
{
$career_solution = $career_solution->where('city', '=',$data['city']);
}
if(!empty($data['radius']))
{
$career_solution = $career_solution->where('radius', '=',$data['radius']);
}
if(!empty($data['employment_type']))
{
$career_solution = $career_solution->where('employment_type', '=',$data['employment_type']);
}
if(!empty($data['estimated_salary']))
{
$career_solution = $career_solution->where('estimated_salary', '=',$data['estimated_salary']);
}
if(!empty($username))
{
$career_solution = $career_solution->whereHas('user', function ($query) use ($username) {
$query->where('users.username', '=', $username);
});
}
if (!Sentinel::check())
{
$career_solution = $career_solution->Where(function ($query){
$query->whereHas('user.privancy_setting', function ($query) {
$query->where('privacy_settings.career_solutions', '=', 0);
})->where('public','=',1);
});
}
if ($user = Sentinel::check())
{
$id = $user->id;
$career_solution = $career_solution->orWhere(function ($query1) use($id) {
$query1->Where(function ($query2) use($id) {
$query2->whereHas('user.privancy_setting', function ($query3) {
$query3->where('privacy_settings.career_solutions', '=', 0);
})->where('public','=',1);
})->orWhere(function ($query4) use($id) {
$query4->whereHas('user.contact', function ($query5) use ($id) {
$query5->where('contacts.user_id', '=', $id);
});
});
});
$career_solution = $career_solution->Where('user_id','=',$id);
}
$career_solution = $career_solution->limit(9000);
/* $data['career_solutionsCount'] = $career_solution->count();
$data['career_solutions'] = $career_solution->orderBy('id', 'desc')->skip($offset)->take($perPage)->get();
$data['paginator'] = new Paginator($data['career_solutions'],$data['career_solutionsCount'], $perPage, $page,
['path' => Request::url()]
);*/
$career_solutions = $career_solution->orderBy('date', 'desc')->get();
$data['career_solutionsCount'] = $career_solutions->count();
$data['career_solutions'] = CareerSolution::customPaginate($page,$career_solutions,12)->setPath(Request::url());
$meta_content = MetaContent::where('url', '=', 'search-career-solutions')->first();
$data['meta_description'] = $meta_content->meta_description;
$data['meta_title'] = $meta_content->meta_title;
return view('career_solution.search_career_solution',$data);
}
在我的控制台中,其值从1变为0,从0变为1,但是搜索仅适用于value=1
。对于value=0
,此输入无效。 form:select
,value=0
的选项有效。您知道为什么吗?