azdfg1 azdfg1 - 1 year ago 172
PHP Question

Laravel button does not link to route


<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>{{ $id->title }}</h1>

<ul class="list-group">
@foreach($id->notes as $note)
<li class="list-group-item">
{{ $note->body }}
<span class="pull-right">
<button href="/notes/{{ $note->id }}/edit" type="button" class="label label-default pull-xs-right">Edit</button>

<h3>Add a New Note</h3>

<div class="form-group">
<form method="post" action="/cards/{{ $id->id }}/notes">
<div class="form-group">
<textarea name="body" class="form-control"></textarea>
<div class="form-group">
<button type="submit" class="btn btn-primary">Add Note</button>

The button in the foreach loop has the correct link, /note/id/edit. I can type that into chrome and go to the edit page. However, the button does not head there. I just see the click animation. Why would this be?

Answer Source

Button element does not have the href attribute so you can either wrap it in a link tag like this. and this is the easiest way

<a href="{{"/notes/". $note->id. "/edit"}}" >
<button type="button" class="label label-default pull-xs-right">Edit</button

or you cab wrap it in a form element and set the action attribute to your desired link like this.

<Form method="get" action="{{"/notes/". $note->id. "/edit"}}">
<button type="button" class="label label-default pull-xs-right">Edit</button>

the 3rd way is to use javascript and onclick listener.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download