Search code examples
phphtmllaravelurlhref

Laravel ,can't put php in the href link


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


Solution

  • 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');