简体   繁体   English

抓住刀片中的ID号

[英]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? 在刀片中如何访问相同的{item} ID号?

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. 您将返回compact('item') ,它会在刀片模板中为您提供$item

You can use it within blade syntax, just like this: 您可以在刀片语法中使用它,如下所示:

{{ $item->id }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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