我发布了一个帖子,其中有标题,内容,图像和类别,一切正常。我想添加一部分PDF文件来发布。
我要上传pdf文件,对于我已经制作的图像
它是web.php \
Route :: post('/ post / store',['uses'=>'PostController @ store','as'=>'post.store']);
控制器 公共功能存储(请求$ request) {
$this->validate($request, [
'title' =>'required',
'featured'=>'required|image',
'content'=>'required',
'category_id'=>'required'
]);
$featured= $request->featured;
$featured_new_name=time().$featured->getClientOriginalName();
$featured->move('uploads/posts', $featured_new_name);
$post = Post::create([
'title'=>$request->title,
'content'=>$request->content,
'featured'=>'uploads/posts/'. $featured_new_name,
'category_id'=>$request->category_id,
'slug'=>str_slug($request->title)
]);
Session::flash('success', 'New Blog has been Published on Website for
Particular Menu');
return redirect()->back();
}
post.blade.php
@extends ('layouts.app')
@section('content')
@if(count($errors)>0)
<ul class="list-group">
@foreach($errors->all() as $error)
<li class="list-group-item text-danger">
{{$error}}
</li>
@endforeach
</ul>
@endif
<div class="panel panel-default" >
<div class="panel-heading">
<div class="text-center">
<b> Create a new Blog</b>
</div>
</div><BR>
<div class="panel-body">
<form action="{{route('post.store')}}" method="post"
enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group">
<label for ="title">Title</label>
<input type="text" name="title" class="form-control text-danger">
</div>
<div class="form-group">
<label for ="featured">Image/Featured</label> <input type="file" name="featured" class="form-control">
</div>
<div class="form-group table-dark">
<label for ="category">Select a Menu</label>
<select name="category_id" id="category" class="form-control" >
@foreach($categories as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for ="content">Content</label>
<textarea name="content" id="content" cols="5" rows="5" class="form-control"> </textarea>
</div>
<div class="form-group">
<div class="text-center">
<button class="btn btn-success" type="submit"> Submit Blog</button>
</div>
</div>
</form> </form>
</div>
</div>
@停止
@section('styles')
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.css" rel="stylesheet">
@停止
@section('scripts')
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.js"></script>
<script>
$(document).ready(function() {
$('#content').summernote();
});
</script>
@停止