I think there is no error but Laravel shows the following error:
Undefined variable: jobs
public function jobCreate(Request $request){
$data['jobs'] = DB::table('jobs')->get();
$job_category = JobCategory::all();
// $job_locations = JobLocation::all();
if(Auth::user()->user_type == 'admin'){
return view('backend.job_circuler.create',compact('job_category',$data));
}
elseif(Auth::user()->user_type == 'customer'){
return view('frontend.user.job_circuler.create', compact('job','job_category'));
}
else {
abort(404);
}
}
I import all that things properly but not working.
<div class="form-group row" id="location">
<label class="col-md-3 col-from-label">
{{translate('Location')}}
<span class="text-danger">*</span>
</label>
<div class="col-md-9">
<select class="form-control aiz-selectpicker" name="location_id" id="location_id" data-live-search="true" >
<option >select location</option>
@foreach($jobs as $job)
<option value="{{ $job->location_id }}">
{{ $job->joblocation->location }}
</option>
@endforeach
</select>
@error('location')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
</div>
</div>
According to the error message, the view, you've posted is
backend.job_circuler.create
. Am I right?The error says, the variable
$jobs
is missing and it is right: You pass$job_category
as string, but$data
as an array. You indeed can pass arrays tocompact()
but only if they contain variable names instead of actual variables. Why do you even wrap the$jobs
inside$data
?Of course, it also works the other way round:
Or, if you—for some reason—don't want to change the code above the if, you can still do this:
or this: