John Davidson

php - Data as JSON Laravel

0 comments
Message:


Hi i have a search in which it gets data from table candidates


My Search Code


public function advance(Request $request)
{
$data1 = ['LoggedUserInfo'=>Admin::where('id','=', session('LoggedUser'))->first()];
$data = \DB::table('candidates');
if( $request->name){
$data = $data->where('name', 'LIKE', "%" . $request->name . "%");
}
if( $request->location){
$data = $data->where('location', 'LIKE', "%" . $request->location . "%");
}
if( $request->key_skills){
$data = $data->where('key_skills', 'LIKE', "%" . $request->key_skills . "%");
}
if( $request->gender){
$data = $data->where('gender', 'LIKE', "%" . $request->gender . "%");
}
if( $request->pref_loc){
$data = $data->where('pref_loc', 'LIKE', "%" . $request->pref_loc . "%");
}
if( $request->phoneno){
$data = $data->where('phoneno', 'LIKE', "%" . $request->phoneno . "%");
}
if( $request->email){
$data = $data->where('email', 'LIKE', "%" . $request->email . "%");
}
$min_np = $request->min_np;
$max_np = $request->max_np;
if ($min_np || $max_np) {
$data = $data->whereRaw("CONVERT(SUBSTRING_INDEX(notice_period,' ', 1),UNSIGNED INTEGER) >= {$min_np}");
$data = $data->whereRaw("CONVERT(SUBSTRING_INDEX(notice_period,' ', 1),UNSIGNED INTEGER) <= {$max_np}");
}
$min_ctc = $request->min_ctc;
$max_ctc = $request->max_ctc;


if ($min_ctc || $max_ctc) {
$data = $data->whereRaw("CONVERT(SUBSTRING_INDEX(salary,' ', 1),UNSIGNED INTEGER) >= {$min_ctc}");
$data = $data->whereRaw("CONVERT(SUBSTRING_INDEX(salary,' ', 1),UNSIGNED INTEGER) <= {$max_ctc}");
}

if ($request->min_exp || $request->max_exp) {
$data = $data->whereRaw("CONVERT(SUBSTRING_INDEX(experrience,' ', 1),UNSIGNED INTEGER) >= {$request->min_exp}");
$data = $data->whereRaw("CONVERT(SUBSTRING_INDEX(experrience,' ', 1),UNSIGNED INTEGER) <= {$request->max_exp}");
}
// $dataa = $data+;
$data = $data->paginate(10);
$data2 = $data->total();
$dataa = $data->toJson();

$data4 = \DB::table('admins')->get();
$setting = DB::select('select * from logo where id=?',[1]);

return view('search', compact('data2','data4','setting','dataa'))->with('data',$data);
}

Now i want this $data to be converted into an 'Array or JSON'


but when i try this $data->toJson(); it give me this data in pagination with all pages link & paginated data


but i want all data
in a Array or JSON


Note - I want all data at once bcz to export the data into csv file




My Answer:
Auth::user(),'searchData'=>$request->searchData]; $candidates = Candidate::where('name', 'like', '%'.$request->searchData.'%')->get(); return response()->json(['data'=>$candidates]); }

Rate this post

4 of 5 based on 3252 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us