Support the ongoing development of →
Views Blade
Last updated 1 year ago.

You are using single quotes <a href="{{ route('purchase/$item->id') }} ">, so you will always get same route, try

<a href="{{ route("purchase/$item->id") }} ">
<a href="{{ route('purchase/'.$item->id) }} ">
Last updated 1 year ago.

Hmm I got this as a result: Route [purchase/$item->id] not defined. (View: /Applications/MAMP/htdocs/ec/app/views/general/buy.blade.php) I tried both.

Last updated 1 year ago.

You cannot qoute objects. You would have to do route("purchase/" . $item->id)

But route is a method that returns a URL for a NAMED route and I really hope you haven't hard coded named routes for all these IDs. I would guess that id is a parameter to the route, and in that case it should be passed like this:

route("purchase", ['id' => $item->id]) where "purchase" is the name (the key "as" in routes.php) of the route.

Sorry if formatting is bad, I'm on iPhone.

Last updated 1 year ago.

It worked! Thank you so much! But there's a minor issue. It's returning the following URL:


Is there a way to have a cleaner URL, like this


Here's my code

@foreach (array_chunk($items->all(), 3) as $item_each)
                        @foreach($item_each as $item)
                            <a href="{{ route("purchase", ['id' => $item->id]) }} ">
                              {{ HTML::image($item->image_url, 'item-image', array('class' => 'item-image-row')) }}
                              <h4>{{ $item->item }}</h4>
                              <span class="text-muted">{{ $item->cost }}</span>
Last updated 1 year ago.

Yes it is - in the route. Show that file. It should be something like

Route::get('purchase/{id}', ['as' => 'purchase' ........

Notice the /{id} part (which defines the actual URL)

Last updated 1 year ago.

I tried doing that. But it still has a question mark that I'm trying to get rid of:


Here is my code:

Route::group(['prefix' => 'purchase'], function()
        'as' =>'purchase',
        'uses' => 'PurchaseController@getPurchase'

    Route::get('/{id}', array(

Last updated 1 year ago.

I don't see any question ;)

But if you mean the "public" in your URL, that has to be handled on webserver level (normally with vhost).

If it is the parenthesis, try changing place of the routes. The less exact should be at the bottom. Ie, it evaluates routes from top -> bottom.

Last updated 1 year ago.

I meant the question mark between the "purchase" and the "iphone4s". I'm taking in the paramater after the "purchase/" and I'm going to use it as a wild card so i can get that specific item's properties. Not sure if i can do that if there's a question mark

Last updated 1 year ago.

Sign in to participate in this thread!


Your banner here too?

amilajack amilajack Joined 19 Jul 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.