Which error do you get? And could you please edit the question, some of the code is not in the code area, it is hard to read?
Sep 11, 2018
4
Level 1
Content submitted fail to be inserted into database
Hello guys please help me out. I have done a page where user can enter data (title,category,image and content) but it does not seems to work and it shows no errors.
Posts 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(); /*symfony function to give name for the file uploaded*/
$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
]);
}
Create Post page
Create Post<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">
</div>
<div class="form-group">
<label for="featured">Featured Image</label>
<input type="file" name="featured" class="form-control-file">
</div>
<div class="form-group">
<label for="category">Select a category</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 class="form-control" id="content" rows="3"></textarea>
</div>
<div class="form-group">
<div class="text-center">
<button class="btn btn-success" type="submit">
Save Post
</button>
</div>
</div>
</form>
</div>
Routes
Route::get('/post/create',[
'uses'=>'PostsController@create',
'as'=>'post.create'
]);
Route::post('/post/store',[
'uses'=>'PostsController@store',
'as'=>'post.store'
]);
Post Model
Level 104
Your <textarea id="content"> has no name attribute, so it will not be submitted leading to a validation failure (as it is required)
Please or to participate in this conversation.