I have made a post, in which I have title, content, image and category , all is working fine. I want to add a section of PDF file to post.
I want to upload a pdf file, For image I have made already
it's web.php \
Route::post('/post/store', [ 'uses' => 'PostController@store', 'as' => 'post.store' ]);
Controller public function store(Request $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">
</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="" method="post"
enctype="multipart/form-data">
<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=""></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>
@stop
@section('styles')
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.css" rel="stylesheet">
@stop
@section('scripts')
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote.js"></script>
<script>
$(document).ready(function() {
$('#content').summernote();
});
</script>
@stop
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire