0

i just want to make a button redirecting me to something like this"/loans/loans->id/edit"

where loans->id is from database, how should he href look?

<button href="{{ URL('/loans/{{$loan->id}}/edit')}}" 

This is what i have until now and is giving error

3 Answers 3

1

You are writing blade braces inside of another which will throw a Parse error. Because it will translate into this piece of code.

<button href="<?php echo e(URL('/loans/{{$loan->id); ?>/edit')}}" 

Also if you want to write an expression inside of a string then use double quotes "" and {} single curly brace.

Try this.

<button href="{{ URL("/loans/{$loan->id}/edit") }}" 

Also in your routes file add this route.

Route::get('/loans/{id}/edit', 'controller@method');
Sign up to request clarification or add additional context in comments.

7 Comments

yes.First marks is going to end the parameter for href so /loans/{$loan->id}/edit") }}" is not going to enter in href
@Andrei You're confused about quotes. because the first quote is nothing to do with the quotes inside blade braces because these are HTML attribute quotes not PHP quotes. Your blade code starts from {{
@Andrei Laravel will translate this code inside {{ }} into this <button href="<?php echo e(URL("/loans/{$loan}/edit")); ?>">
it worked.i use visual code and when i pasted your code in it ,was not looking very good
@Andrei Oh haha :-) visual studio code's highlighter doesn't support this deep nested quotes very well.
|
0

first href you need to write in the tag a! You can use the helper route

<a htef="{{route('loans.edit',[$loans->id])}}">link</a>

and in the file of the router, write

 Route::get('loans/{$id}/edit', 'yourcontroller@method')->name('loans.edit')

2 Comments

what method should i use?
Are you talking about this? 'yourcontroller@method' .your method in controller.
0

Your href should be like

href='loans/{{$load->id}}/edit'

And you should have the following inside your \routs\web.php

Route::get('/loans/{loan}/edit', 'LoansController@edit');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.