I am new to laravel and i am trying to refresh a div in my page using JQuerys .load() function however, Every-time i get an internal error 500 i have been playing and messing around for an hour now and can't find a solution to my problem, Even though it is a get request i still have my CSRF token in the meta tag on the layout i am extending. I am just using
php artisan not xampp for the server and i am on a mac, My current path is open to 777 , so i can't see this being a file permissions error
My route for the .load() request
Route::get('/employee/applied/{id}', 'EmployeesController@load')->middleware('auth');
My Controller to handle the .load() url
public function load($id) {
$applicants = array();
$applied = Applied::where(['job_id' => $id])->get();
foreach($applied as $employee) {
$employee_object = Employee::where(['employee_id' => (string)$employee->employee_id])->get();
foreach($employee_object as $information) {
$applicants[] = $information;
}
}
return view('employer.appliedEmployee')->with('applied', $applicants);
}
The view the .load() is loading
<div class="w3-container w3-padding-16">
<?php $col = 1; ?>
@foreach($applied as $applied)
<?php if($col == 5) {$col = 1; echo '<div class="w3-row">'; } ?><!-- Start -->
<div class="w3-col m3 s12 w3-container w3-padding-16">
<div class="w3-card-4 test" style="width:92%;max-width:300px;">
<img src="https://employee.hopp2.co/user_data/profile/" alt="Avatar" style="width:100%; height: 250px; opacity:0.85">
<div class="w3-container">
<h4><b></b></h4>
<p><small><b>Location:</b> </small></p>
<div class="">
<p><a class="w3-button w3-green w3-hover w3-half" href="/employee/show/">Resume</a></p>
<p><button class="w3-button w3-yellow w3-hover w3-half" href="/employee/view/">hire</button></p>
</div>
<div class="w3-padding-16"><hr></div>
</div>
</div>
</div>
<?php $col += 1; if($col == 5) { echo '</div>'; } ?><!-- Finish -->
@endforeach
</div>
The page that is loading everything
@extends('employer.layouts.app')
@section('content')
<div class="w3-container">
<b><a href="">Back</a></b>
<div id="applied">
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var refresh = setInterval(
function(){
$('#applied').load('<?php echo url('/employee/applied/'.$getID.'');?>');
console.log('yes');
},5000
);
window.onload = refresh;
</script>
@endsection
and finally the controller that is loading that page
public function show($id)
{
$employerId = Auth::id();
$currentJobs = jobs::where(['employer_id' => (string)$employerId, 'closed' => 0, 'id' => $id ])->get();
if($currentJobs->isEmpty()) {
return redirect('/Jobs//');
} else {
$getID = $id;
return view('employer.appliedEmployee')->with('getID', $getID);
}
}
I am very stuck and i am not expecting a spoon feed answer just some guidance because i can not find the solution to this at the moment on the internet any feedback would be great thank you.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire