vendredi 21 juillet 2017

what's wrong with my create view in laravel

I can't figure out what's wrong with my create view. I need the submit button to redirect me to my show view so I can see all the created tags. Here are the routes to create a tag, to show the tag and then store the tag:

Route::get('/tags/create', ['uses' => 'TagController@create', 'as' => 'tags.create']); //  Allows you to create a new tag

Route::post('/postTags', ['uses' => 'TagController@store', 'as' => 'postTags']); //    Place where all the tags are stored

Route::get('/tag/show', ['uses' => 'TagController@show', 'as' => 'tags.show']); //  Shows you all the existing tags

Here is my tag controller:

public function create()
{
    $tag = new Tag();
    return view('tags.create', compact('tag'));
}

public function store(Request $request)
{
    $this->validate($request, [
        'name' => 'required',
    ]);

    $tag = new Tag;
    $tag->name = $request['name'];
    $tag->save();

    return redirect()->route("tags.show");
}
public function show()
{
    $tags = Tag::all();
    return view('tags.show', compact('tags'));
}

And my create view:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>New Tag</h1>
<form method="POST" action="">

    

    <label for="name">Click here to edit the title of your post!</label>
    <input type="text" name="Name" id="name" required/>
    <input type="submit" value="Submit" onclick="window.location=''"/>
</form>
</body>
</html>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire