'cover image must be an image in laravel 8
Im new with laravel 8, I have been trying uploading a form with a file field but I keep getting an error image must be an image even though I have enctype='multipart/form-data' included in a form. I real need your help.
Blade Template
@extends('layouts.app')
@section('contents')
<div class="container">
<h1> Create a Posts</h1>
{!! Form::open(['action' =>['App\Http\Controllers\PostController@store','enctype'=>'multipart/form-data', 'method'=>'POST']]) !!}
<div class="form-group">
{{Form::label('title', 'Title')}}
{{Form::text('title','',['class'=>'form-control','placeholder'=>'Title'])}}
</div>
<div class="form-group">
{{Form::label('body', 'Body')}}
{{Form::textarea('body','',['class'=>'form-control','id'=>'article-ckeditor','placeholder'=>'Bodytext'])}}
</div>
<br>
<div class="form-group">
<div class="image">
{{Form::file('cover_image')}}
</div>
</div>
<br>
{{Form::submit('Submit',['class'=>'btn btn-primary']);}}
{!! Form::close() !!}
</div>
@endsection
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Post;
use App\Models\User;
public function store(Request $request)
{
$validatedData = $request->validate([
'title' => ['required', 'unique:posts', 'max:500000'],
'body' => ['required'],
'cover_image'=>['image','nullable','max:19999']
]);
//handle file uploads
if($request->hasfile('cover_image')){
return '123';
}
}
routes Route::resource('/post', PostController::class);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
