I added file upload feature to my controller but, it isn't working. I keep running into this error.
failed to open stream: No such file or directory
I've linked the storage, cleared cache and virtually everything I know, can someone help me figure what's wrong.
Controller
class CandidatesController extends Controller
{
public function create(Request $data)
{
try {
$this->validate($data, [
'middle_name' => ['required', 'string', 'max:255'],
'what_i_do' => ['required', 'string', 'max:255'],
'phone' => ['required', 'string', 'max:20'],
'age' => ['required', 'date', 'max:255'],
'gender' => [
'required',
Rule::in(['male', 'female', 'others']),
],
'religion' => ['nullable', 'string', 'max:255'],
'address_1' => ['required', 'string', 'max:255'],
'address_2' => ['required', 'string', 'max:255'],
'city' => ['required', 'string', 'max:255'],
'highest_qualification' => [
'required',
Rule::in([
'no formal education', 'primary school', 'secondary school', 'technical school', 'nce', 'nd1',
'nd2', 'bsc', 'pgd'
]),
],
'discipline' => ['nullable', 'string', 'max:255'],
'lga' => ['required', 'string', 'max:255'],
'state' => ['required', 'string', 'max:255'],
'country' => ['required', 'string', 'max:255'],
'status' => [
'required',
Rule::in(['hired', 'hunting', 'vacation']),
],
'skills' => ['required', 'string'],
'about' => ['required', 'string'],
'fb_url' => ['nullable', 'string'],
'twt_url' => ['nullable', 'string'],
'ig_url' => ['nullable', 'string'],
'ext_url' => ['nullable', 'string'],
'lnkd_url' => ['required', 'string'],
'img_url' => ['nullable', 'mimes:jpeg,png,jpg,gif,svg', 'max:2048'],
'cv_url' => ['nullable', 'mimes:pdf,doc,docx', 'max:4000'],
]);
if ($data->hasFile('img_url')) {
$user_img = $data->img_url;
$ext = $user_img->getClientOriginalExtension();
$pro_img = random_bytes(7).'.'.$ext;
$img_path = $data->file('img_url')->storeAs('public/pics', $pro_img);
} else {
$img_path = 'default_img.jpg';
}
if ($data->hasFile('cv_url')) {
$user_cv = $data->file('cv_url');
$cv_ext = $user_cv->getClientOriginalExtension();
$cand_cv = random_bytes(7).'.'.$cv_ext;
$cv_path = $data->file('cv_url')->storeAs('public/cvs', $cand_cv);
} else {
$cv_path = 'no file uploaded';
}
return redirect('/');
} catch (Illuminate\Database\QueryException $th) {
return redirect('/candidate-register')->withError($th->getMessage())->withInput();
}
}
}
Don't mind me validating in the controller; I'm just trying to get everything working before cleaning it up