【发布时间】:2019-11-23 02:26:36
【问题描述】:
我是 laravel 和 php 的新手。
鉴于下面的代码,我希望用户在单击列表中的属性后导航到特定于属性的详细信息。
我正在尝试通过将用户发送到“属性详细信息”模板来动态显示特定属性信息,因此我没有为每个属性设置单独的页面。
我很尴尬地说我花了多少时间试图弄清楚这一点。
//WebController.php
function properties(Request $request) //for the property list page
{
$data = array (
'title' => "Our Properties"
);
return view('p',["properties" => $this->data()])->with($data);
}
function sub_prop($id) //for the property details template page
{
$data = array (
'title' => $id
);
return view('properties.template', ['properties' => $this->data()])->with($data);
}
//web.php
Route::get('properties/{id}', 'WebController@sub_prop');
//Fake database
function data(){
return array(
array(
'name' => "Carpenter",
'address' => array(
'name' => "address", //I realize this is redundant
'street' => "address",
'city' => "city",
'zip' => "zip"
)
),
array(
'name' => "Berkman",
...etc
//property_list_page.blade.php
<div id="property-grid-2" class="container-grid ">
@foreach($properties as $property)
<div class="card-container">
<h3 class="a " id="propName">
@if(isset($property['name']))
<b>{{ $property['name'] }}</b></h3>
@else
<b>Dream Home</b></h3>
@endif
<div class="card">
<a id="propLinker" href="property/{{$property['name']}} ">
//the above href is for the dynamic link
插入到 href 中的 php 回退了“'name' is an undefined index.”的错误。但是如果我删除href中的代码,它所在的foreach循环执行得很好......
我已经尝试了无数种将 php 插入到 href、使用 addEventListener 的 ajax 调用等等的排列方式……我很难过。感谢您的帮助。
【问题讨论】: