in Education by
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
@if($errors->has('setor_id')) {{$errors->first('setor_id')}} @endif
@if($errors->has('mes')) {{$errors->first('mes')}} @endif
@if($errors->has('ano')) {{$errors->first('ano')}} @endif
@if($errors->has('andon')) {{$errors->first('andon')}} @endif
@if($errors->has('conteudo')) {{$errors->first('conteudo')}} @endif
@if($errors->has('atividade_total')) {{$errors->first('atividade_total')}} @endif
@if (count($errors) > 0)
Whoops! There were some problems with your input.

    @foreach ($errors->all() as $error)
  • {{ $error }}
  • @endforeach
@endif
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)

1 Answer

0 votes
by
Your form needs to have the enctype="multipart/form-data" attribute to upload images.

Related questions

0 votes
    This question already has answers here: How do I properly escape quotes inside HTML attributes? (6 answers) Closed 3 years ago....
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    How to get array from form validation config file in controller? application/config/form_validation.php I have ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    How to get array from form validation config file in controller? application/config/form_validation.php I have ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    In Laravel, there is a function return back();, which returns the user to the previous page. Is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I have a question. If created_at in my database is datetime and I want to make a query like this ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I have a question. If created_at in my database is datetime and I want to make a query like this ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I have a question. If created_at in my database is datetime and I want to make a query like this ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    When I have started with the project using Laravel 5.7 and PHP 7.3, $info->id returned correctly the last insert id. Now, I did ... :1 [ 0 => "*" ] } This is my GfTableModel.php:...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    When I have started with the project using Laravel 5.7 and PHP 7.3, $info->id returned correctly the last insert id. Now, I did ... :1 [ 0 => "*" ] } This is my GfTableModel.php:...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I have a table structure like this : subscribers with attributes: id, status I want to have a way ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I am using Laravel Image Intervention to resize an image upload field on my form. This is the error ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 30, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I want to load Google fonts in the head-section of my page using a php-function. My -area looks like this: ... ... Now ... I do this, there will be a "1" displayed (because of the...
asked May 17, 2022 in Education by JackTerrance
...