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") }} ">
//or
<a href="{{ route('purchase/'.$item->id) }} ">
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.
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.
It worked! Thank you so much! But there's a minor issue. It's returning the following URL:
http://localhost:8888/ec/public/purchase?id=iphone4s
Is there a way to have a cleaner URL, like this
http://localhost:8888/ec/public/purchase/iphone4s
Here's my code
@foreach (array_chunk($items->all(), 3) as $item_each)
<tr>
@foreach($item_each as $item)
<td>
<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>
</a>
</td>
@endforeach
</tr>
@endforeach
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)
I tried doing that. But it still has a question mark that I'm trying to get rid of:
http://localhost:8888/ec/public/purchase?iphone4s
Here is my code:
Route::group(['prefix' => 'purchase'], function()
{
Route::get('/',[
'as' =>'purchase',
'uses' => 'PurchaseController@getPurchase'
]);
Route::get('/{id}', array(
'as'=>'id',
'uses'=>'ItemController@getItemView'
));
});
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.
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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community