[Solved] Writing a function in laravel


You’re really missing out on the best parts of Laravel’s query builder.

public function jobsearch(Request $request) {
    // htmlspecialchars makes no sense here
    $keyword = $request->input('keyword');
    $city_id = $request->input('city_id');
    $category_id = $request->input('category_id');

    $query = DB::table('job_details');

    if($keyword) {
        $query->where('job_title', 'like', '%'.$keyword.'%');
    }

    if($city_id) {
        $query->where('city_id', $city_id);
    }

    if($category_id) {
        $query->where('category_id', $category_id);
    }

    $results = $query->get();

    foreach($data as $data) { ... }
}

0

solved Writing a function in laravel