You need to add enctype attribute to your form.
<form action="/agendas" method="post" enctype="multipart/form-data">
....
</form>
Hey all, I have a quick form that holds an input for a date, as well as two inputs, each for a file. I'm hoping to store the files in respective folders, and pass the path of the file into the database once it's uploaded. I intentionally have separated inputs, I don't think a multiple-input wouldn't be ideal as the files should be stored separately. Unfortunately, when I submit my form I get the error:
Call to a member function store() on null
My relevant function withing my Controller when I submit the form is this:
public function store(Request $request)
{
//Validate
$request->validate([
'date' => 'required',
'agenda' => 'required',
'minutes' => 'required'
]);
$agenda = Agenda::create([
'date' => $request->date,
'agendaPath' => $request->file('agenda')->store('uploads'),
'minutesPath' => $request->file('minutes')->store('uploads')
]);
return redirect('/agendas/'.$agenda->id);
}
My form within my view looks like this:
<form action="/agendas" method="post">
{{ csrf_field() }}
<div class="form-group">
<label for="date">Meeting Date</label>
<input type="date" class="form-control" name="date">
</div>
<div class="form-group">
<label for="agenda">Agenda File</label>
<input type="file" class="form-control" name="agenda">
</div>
<div class="form-group">
<label for="minutes">Minutes File</label>
<input type="file" class="form-control" name="minutes">
</div>
<input type="submit" class="btn btn-primary">
</form>
My corresponding Model looks like this:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Agenda extends Model
{
protected $table = 'agendas';
protected $dates = ['date', 'created_at', 'updated_at'];
protected $fillable = ['date' , 'agendaPath', 'minutesPath'];
}
Any help would be appreciated with this. Do I need to define a separate function to upload these and call it from within 'store'?
Please or to participate in this conversation.