Skip to content

Commit

Permalink
Job display and searching feature has been added
Browse files Browse the repository at this point in the history
  • Loading branch information
surajitbasak109 committed Jan 5, 2021
1 parent dbc3341 commit 9447221
Show file tree
Hide file tree
Showing 63 changed files with 20,336 additions and 1,037 deletions.
2 changes: 1 addition & 1 deletion .vim-bookmarks
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
let l:bm_file_version = 1
let l:bm_sessions = {'default': {'/home/techcet/code/spotrix/resources/js/components/search/TitleSkillSearch.vue': [{'sign_idx': 9501, 'line_nr': 42, 'content': ' methods: {'},],}}
let l:bm_sessions = {'default': {'/home/techcet/code/spotrix/resources/js/components/search/TitleSkillSearch.vue': [{'sign_idx': 9501, 'line_nr': 42, 'content': ' methods: {'},],'/home/techcet/code/spotrix/resources/js/components/user/job/ApplyButton.vue': [{'sign_idx': 9502, 'line_nr': 149, 'content': ' };'},{'sign_idx': 9501, 'line_nr': 75, 'content': ' <div class="resume-left">PDF</div>'},{'sign_idx': 9504, 'line_nr': 111, 'content': ' </div>'},],}}
let l:bm_current_session = 'default'
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class JobController extends Controller
*/
public function index()
{
$jobs = Job::with('user:users.id,name', 'category:categories.id,name')->get();
$jobs = Job::latest()->with('user:users.id,name', 'category:categories.id,name')->get();
return view('admin.jobs.index', compact('jobs'));
}

Expand Down
189 changes: 131 additions & 58 deletions app/Http/Controllers/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ class FrontController extends Controller
public function index()
{
//$jobColumns = ['id', 'title', 'type', 'city_id', 'deadline', 'monthly_salary_min', 'monthly_salary_max', 'created_at', 'gender', 'company_name', 'slug'];
$jobs = Job::latest()->with(['city:cities.id,name', 'category:categories.id,name'])->active()->paginate(10);
//return $jobs;
$jobs = Job::latest()->with([
'applications:applications.job_id,user_id',
'city:cities.id,name',
'category:categories.id,name',
'skills:id,name'
])->active()->paginate(10);

if (Auth::check()) {
if (Auth::user()->hasRole('user')) {
return view('auth.landing', compact('jobs'));
Expand All @@ -31,85 +36,152 @@ public function index()

public function search(Request $request)
{
$keywords = $request->keywords;
$location = $request->location;
return $request;
$city = $request->city;
$title = $request->title;
$skills = $request->skill;
$term = strtolower($request->term);

if ($title) {
$jobs = Job::active()->latest()
->with([
'applications:applications.job_id,user_id',
'city:cities.id,name',
'category:categories.id,name',
'skills:id,name'
])
->where('title', 'like', $title . '%')
->orWhere('title', 'like', $term . '%')
->paginate(10);
}

if ($skills) {
$jobs = Job::active()->latest()->with([
'applications:applications.job_id,user_id',
'city:cities.id,name',
'category:categories.id,name',
'skills:id,name'
])
->whereHas('skills', function ($query) use ($skills, $term) {
$query->where('name', 'like', $skills . '%')
->orWhere('name', 'like', $term . '%');
})
->paginate(10);
}

if ($city) {
$jobs = Job::active()->latest()->with([
'applications:applications.job_id,user_id',
'city:cities.id,name',
'category:categories.id,name',
'skills:id,name'
])
->whereHas('city', function ($query) use ($city, $term) {
$query->where('name', 'like', $city . '%')
->where('name', 'like', $term . '%');
})
->paginate(10);
}
return view('auth.landing', compact('jobs'));
}

public function jobSkillSearch(Request $request)
public function ajaxSearch(Request $request)
{
$term = strtolower($request->term);
if (!$term) abort(404);
$jobs = Job::active()->with('skills:id,name')->where('title', 'like', '%' . $term . '%')
->orWhereHas('skills', function ($query) use ($term) {
$query->where('name', 'like', '%' . $term . '%');
})
->orderBy('id')->limit(8)->get(['id', 'title']);

// define an empty array
$searches = [];

// loop through all jobs
foreach ($jobs as $job) {
if (strpos(strtolower($job->title), $term)) {
$searches[] = strtolower($job->title);
}
$title = $request->title;
$skills = $request->skills;
$city = $request->city;

foreach ($job->skills as $skill) {
$skills = $skill->name;
$searches[] = strtolower($skills);
}
if ($title) {
$title = strtolower($title);
if (!$title) abort(404);
$jobs = Job::active()->latest()->where('title', 'like', $title . '%')
->get(['title']);

return $jobs;
}

$search_data = !empty($searches) ? array_unique($searches) : [];
if (!empty($search_data)) {
if ($skills) {
$skills = strtolower($skills);
$jobs = Job::active()->latest()->with('skills:id,name')
->whereHas('skills', function ($query) use ($skills) {
$query->where('name', 'like', $skills . '%');
})
->get(['id']);

// define an empty array
$searches = [];
foreach ($search_data as $data) {
// echo strtolower($data) . "\n";
if (strpos($data, $term) !== false) {
$searches[] = Str::limit($data, 20);

// loop through all jobs
foreach ($jobs as $job) {
foreach ($job->skills as $skill) {
$skill_name = $skill->name;
$searches[] = strtolower($skill_name);
}
}

$search_data = !empty($searches) ? array_unique($searches) : [];
// return $search_data;
if (!empty($search_data)) {
$searches = [];
foreach ($search_data as $data) {
// echo strtolower($data) . "\n";
if ($data[0] == $skills[0]) {
$searches[] = Str::limit($data, 20);
}
}
}

return $searches;
}

return $searches;
}
if ($city) {
$city = strtolower($request->city);
$jobs = Job::active()->latest()->with(['city:cities.id,name'])
->whereHas('city', function ($query) use ($city) {
$query->where('name', 'like', $city . '%');
})
->limit(8)->get(['id', 'city_id']);

public function jobCitySearch(Request $request)
{
$term = strtolower($request->term);
if (!$term) abort(404);
$jobs = Job::active()->with(['city:cities.id,name'])
->whereHas('city', function ($query) use ($term) {
$query->where('name', 'like', '%' . $term . '%');
})
->orderBy('id')->limit(8)->get(['id', 'city_id']);

// define an empty array
$searches = [];

// loop through all jobs
foreach ($jobs as $job) {
if (strpos(strtolower($job->city), $term)) {
$searches[] = $job->city->name;
// define an empty array
$searches = [];

// loop through all jobs
foreach ($jobs as $job) {
if (strpos(strtolower($job->city), $city)) {
$searches[] = $job->city->name;
}
}
}

$searches = !empty($searches) ? $searches : [];
$searches = !empty($searches) ? $searches : [];

return $searches;
}

return $searches;
return [];
}

public function job(Job $job, Request $request)
{
$jobs = Job::active()->latest()->paginate(10);
//return $job;
return view('job.show', compact('job', 'jobs'));
$applicationUserIds = $job->applications->pluck('user_id')->toArray();
$jobs = Job::active()->with(['applications:applications.job_id,user_id', 'city:cities.id,name', 'category:categories.id,name'])->latest()->paginate(10);
// return $jobs;
return view('job.show', compact('job', 'jobs', 'applicationUserIds'));
}

public function apply($job_id, User $user, Request $request)
{

$application = Application::where(['user_id' => $user->id, 'job_id' => $job_id])->first();

if ($application) {
return response()->json(['message' => 'You already applied for this job'], 403);
}

$this->validate($request, [
'email' => ['required', 'email'],
'phone' => ['required', 'string'],
'resume' => ['nullable', 'file']
]);

$profile = $user->profile;
$resume = $request->file('resume');
$allowed_extensions = ['doc', 'docx', 'pdf', 'jpg', 'jpeg'];
Expand Down Expand Up @@ -144,6 +216,7 @@ public function apply($job_id, User $user, Request $request)
}

$profile->cv = $cvName;
$profile->phone = $request->phone;
$profile->save();

$application = new Application();
Expand All @@ -154,6 +227,6 @@ public function apply($job_id, User $user, Request $request)
$application->resume = $cvName;
$application->save();

return redirect()->route('welcome')->with('success', 'Application saved');
return response()->json(['success' => true, 'message' => 'Application saved']);
}
}
2 changes: 2 additions & 0 deletions app/Http/Controllers/User/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function store(Request $request)
'image' => 'nullable|file',
'job_type' => 'nullable|integer',
'jobrole' => 'nullable|string',
'phone' => 'nullable|string',
'location' => 'nullable|string',
'skills' => 'nullable|string',
'education' => 'nullable|string',
Expand Down Expand Up @@ -124,6 +125,7 @@ public function store(Request $request)
$user->update();

$profile->jobrole = $request->jobrole;
$profile->phone = $request->phone;
$profile->image = $imageName;
$profile->cv = $cvName;
$profile->education = $request->education;
Expand Down
12 changes: 11 additions & 1 deletion app/Models/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@

class Application extends Model
{
use HasFactory;
use HasFactory;
protected $guarded = [];

public function job()
{
return $this->belongsTo('App\Models\Job');
}

public function user() {
return $this->belongsTo('App\Models\User');
}
}
5 changes: 5 additions & 0 deletions app/Models/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public function city()
return $this->belongsTo('App\Models\City');
}

public function applications()
{
return $this->hasMany('App\Models\Application');
}

public function scopeActive($query)
{
return $query->whereStatus(true);
Expand Down
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ class User extends Authenticatable
public function profile() {
return $this->hasOne('App\Models\Profile');
}

public function applications()
{
return $this->hasMany('App\Models\Application');
}
}
14 changes: 13 additions & 1 deletion app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function renderExperienceOptions($old = "")
];

foreach ($experience as $key => $experience) {
$selected = empty($old) ? "" : ($experience["value"] == $old ? "selected" : "");
$selected = $experience["value"] == $old ? "selected" : "";
echo '<option ' . $selected . ' value="' . $experience["value"] . '">' . $experience["label"] . '</option>';
}
}
Expand Down Expand Up @@ -174,3 +174,15 @@ function renderGender($type)
}
}
}

if (!function_exists('applicationHasUser')) {
function applicationHasUser($applications, $user_id)
{
foreach ($applications as $appl) {
if ($appl['user_id'] == $user_id) {

return true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function up()
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('jobrole')->nullable();
$table->string('phone')->nullable();
$table->string('image')->default('avatar.jpg');
$table->string('cv')->nullable();
$table->string('education')->nullable();
Expand Down
Loading

0 comments on commit 9447221

Please sign in to comment.