简体   繁体   中英

Grabbing the ID number in a blade

I have a route that takes me to my item page.

Route::get('/items/{item}', 'ItemsController@show');

In this page I have a form if the form is not filled out properly it will redirect to the forms method which currently is

action="/items"

How can I access that same {item} id number while in the blade?

Edit: Here is the Controller code

public function index()
{
  $item = Post::get();
  $price = $item->price;

  return view('item');
}

public function show(Item $item)
{
  return view('item', compact('item'));
}

You're returning compact('item') which gives you $item in your blade template.

You can use it within blade syntax, just like this:

{{ $item->id }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM