@aondoe can you provide code from controller?
Sep 16, 2018
12
Level 1
File upload not working
Hello everyone.
I'm having trouble with file upload in laravel 5.6 I'm trying to upload images to my CMS I've created with Laravel.
I have a table called "post_its" below:
public function up()
{
Schema::create('post_its', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('content');
$table->text('subject');
$table->text('featured_img');
$table->timestamps();
});
}
I had to add a column in the table to upload images so I did so like below:
public function up()
{
Schema::table('post_its', function(Blueprint $table)
{
//add a column to the post_its table and give it 100 characters. Also specify 100 characters
$table->string('featured_img', 100)->nullable();
});
}
Here's my form data I'm trying to fix, as you can see below:
<form action="{{route('posts.update', $post->id)}}" method="POST" type="multipart/form-data">
<!--other form fields are here as well, but omitted for brevity-->
<div class="form-group">
<input type="file" name="featured_img" title="Featured image">
</div>
</form>
Every other field works and updates the database table, but not this upload field. All the fields under the featured_img column says null. I was hoping after I added this column I could edit this column. Any suggestions?
Level 10
Are you updating the Post model via mass assignment in the Controller? If so, make sure you have included featured_img in the $fillable property of your model
1 like
Please or to participate in this conversation.