As I am leaning laravel I am facing directory issues. I have made a navbar in which a create option is given to access the create file which is located in my resources/views/posts/create directory. The problem is that when I click it for the first time it functions fine and in URL shows I have opened posts/create directory which is fine. but if I click it again, it goes in posts/posts/create directory, which results give 404|Not Found error
my files are create.blade.php
@extends('main')
@section('content')
<div class="row">
<div class="col-sm-8 offset-sm-2">
<h1 class="display-3">Add a BLOG</h1>
<div>
<form method="POST" action="">
@csrf
<div class="form-group">
<label for="first_name">Title:</label>
<input type="text" class="form-control" name="title"/>
</div>
<div class="form-group">
<label for="last_name">Body :</label>
<input type="text" class="form-control" name="body"/>
</div>
<button type="submit" class="btn btn-lg btn-primary">Add Blog
</button>
</form>
</div>
@endsection
web.php
Route::resource('posts', 'PostController');
and for controller, I used a resource controller PostController.php
public function create()
{
return view('posts.create');
}
public function store(Request $request)
{
$post = new posts;
$post->title = $request->input('title');
$post->body = $request->input('body');
$post->save();
return redirect('/');
}
Apologies as I know its a very bad way of asking the question but I am finding hard to tell in an easy way
please guide me through it.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire