This is my web.php file where my resource route is present!
Route::group(['namespace' => 'Admin'],function()
{
Route::resource('admin/post','PostController');
});
Here is the post controller function store which is storing my data to the database and the showing it to the panel, it was working fine but after I added the categories and tags requests it just broke up!!
public function store(Request $request)
{
$this->validate($request,
[
'title' => 'required',
'subtitle' => 'required',
'slug' => 'required',
'body' => 'required'
]);
$post = new post;
$post->title = $request->title;
$post->subtitle = $request->subtitle;
$post->slug = $request->slug;
$post->body = $request->body;
$post->save();
$post->tags()->sync($request->tags);
$post->categories()->sync($request->categories);
return redirect(route('post.index'));
}
As I clicked the submit button in this form below:
<form role="form" action="" method="post">
<div class="box-body">
<div class="col-lg-6">
<div class="form-group">
<label for="title">Post Title</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Welcome to the world of reality">
</div>
<div class="form-group">
<label for="subtitle">Post Sub Title</label>
<input type="text" class="form-control" id="subtitle" name="subtitle" placeholder="Here we can grow together">
</div>
<div class="form-group">
<label>Select Tags</label>
<select class="form-control select2 select2-hidden-accessible" multiple="" data-placeholder="Select a State" style="width: 100%;" tabindex="-1" aria-hidden="true" name="tags[]">
@foreach ($tags as $tag)
<option value=""></option>
@endforeach
</select>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="status"> Publish
</label>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="slug">Post Slug</label>
<input type="text" class="form-control" id="slug" name="slug" placeholder="Slug"}}">
</div>
<div class="form-group">
<label>Select Categories</label>
<select class="form-control select2 select2-hidden-accessible" multiple="" data-placeholder="Select a State" style="width: 100%;" tabindex="-1" aria-hidden="true" name="categories[]">
@foreach ($categories as $category)
<option value=""></option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="image" style="margin-top: 10px;">File input</label>
<input type="file" name="image" id="image">
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box box-info">
<div class="box-header">
<h3 class="box-title">Write Post Body Here
<small>(Advanced and full of features)</small>
</h3>
<!-- tools box -->
<!-- /. tools -->
</div>
<!-- /.box-header -->
<div class="box-body pad">
<textarea id="editor1" name="body" rows="10" cols="80">
Here you can write your post.
</textarea>
</div>
</div>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
<a href="" class="btn btn-warning">Back</a>
</div>
</form>
I don't know what is going on why it do this, I also have the update function which update the present post but I don`t create a new one, I don't know why ?
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire