I'm trying to insert data to the database and at the same time uploading an image to the path. It seems the problem is with the validation, but I can't see where is the error. I've been stuck for two days trying to figure out what I'm doing wrong.
Here's the code for the upload:
protected function store(Request $request)
{
$nameFile = null;
if ($request->hasFile('image')) {
$name = uniqid(date('HisYmd'));
$extension = $request->image->extension();
$nameFile = "{$name}.{$extension}";
$upload = $request->image->storeAs('categories', $nameFile);
return $namefile;
}
}
Here's the create function:
protected function create(array $data){
$image = $this->store();
return Bottleneck::create([
'setor_id' => $data['setor_id'],
'mes' => $data['mes'],
'ano' => $data['ano'],
'andon' => $data['andon'],
'conteudo' => $data['coteudo'],
'atividade_total' => $data['atividade_total'],
'image' => $image
]);
}
Here's the validation:
protected function validator(array $data){
return Validator::make($data , [
'setor_id' => ['required', 'integer', 'exists:setor_linha,id'],
'mes' => ['required', 'integer'],
'ano' => ['required', 'integer'],
'andon' => ['required', 'string'],
'conteudo' => ['required', 'string'],
'atividade_total' => ['required', 'string'],
'image' => ['image'],
]);
}
The save function:
public function save(Request $request){
$validation = $this->validator($request->all());
if($validation->fails()){
Session::flash('message', 'Error');
return redirect()->route('bottleneck');
}else{
$bottleneck = $this->create($request->all());
Session::flash('message', 'Success');
return redirect()->route('bottleneck');
}
}
And here's my form:
@csrf
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)