I want to do the following in my blade.php but I get a syntax error:
<a class="btn btn-info" role="button" href="{{ url('/Animal/{{$animal->id}}/edit')}}">Edit Profile</a>
The error is to do with the href attribute I think, how do I correct the syntax?
Error I am getting: enter image description here
You have an error in your code, please try this one.
<a class="btn btn-info" role="button" href="{{ url('/Animal/' . $animal->id . '/edit')}}">Edit Profile</a>
Hope this helps.
Yes you have a syntax error in your code. You can't use {{ }}
inside another {{ }}
.
You have access to php variable inside this first {{ }}
.
Use ""
instead of ''
to use php variables inside a string.
<a
class="btn btn-info"
role="button"
href="{{ url("/Animal/$animal->id/edit") }}"
>
Edit Profile
</a>
The best practice is to use named routes concept. In web.php assign the url with a name.
Route::get('Animal/{id}}/edit','AnimalController@edit')->name('animal.edit');
Now in your view
<a class="btn btn-info" role="button" href="{{ route('animal.edit',['id'=>$animal->id])}}">Edit Profile</a>