Hello. I'm trying to upload files into the public folder. I've already created a link to the storage folder using artisan. But for some reason, the file title uploads to the MySQL field. Has anyone else experienced this?
The main code is in the if-statement near the bottom of the code.
Here is my Controller
public function store(Request $request){
request()->validate([
'title' => 'required|min:2',
'subject' => 'required|min:4',
'content' => 'required|min:50',
'featured_img' => 'sometimes|image'
]);
$this->validate($request, [
'title'=>'required|min:3',
'content'=>'required|min:10',
'featured_image' => 'sometimes|image'
]);
PostIt::create(['title'=>$request->title,
'content'=>$request->content,
'featured_img' => $request->featured_img
]);
if ($request->hasFile('featured_img')){
$path = $request->file('featured_img');
// $fileName=$featured_img->getClientOriginalExtension();
$image->move(base_path('/images'), $fileName);
$post->update(array_merge($request->all(), ['featured_img' => $path]));
return "Here is the path: ".$path;
}
return redirect()->route('posts.index');
}
Here is my form which contains the upload field
<form onsubmit="return confirm('Are you sure you want to edit the post {{$post->title}}?')" action="{{route('posts.update', $post->id)}}" method="POST" type="multipart/form-data">
@method('put')
@csrf
<div class="form-group">
<label for="title" >Title</label>
<input type="text" name="title" id="title" class="form-control" value="{{$post->title}}">
</div>
<div class="form-group">
<h2>Your current subject is {{$post->subject}}</h2>
</div>
<div class="form-group">
<input type="file" name="featured_img">{{$post->featured_img}}
</div>
Any help would be great. Thanks