我创建了一个插件,将其称为“属性”,其中在列表中,我将多个地址字段显示在一列中,该列将组合多个地址字段,如邮政编码、街道类型、门牌号等。
而且我可以在列表中显示它们。下面是我到目前为止为实现它所做的工作。
插件\technobrave\properties\models\property\columns.yaml
columns:
id:
label: Property Address
type: property_address
searchable: true
sortable: false
插件\technobrave\properties\Plugin.php
public function registerListColumnTypes()
{
return [
// A local method, i.e $this->evalUppercaseListColumn()
'property_address' => [$this, 'evalPropertydDetailsListColumn'],
];
}
public function evalPropertydDetailsListColumn($value, $column, $record)
{
$property_array_data = array();
$current_property = Property::where('id', $record->id)->first();
if($current_property)
{
if( ($current_property->lot != NULL) || ($current_property->lot != '') )
{
$property_array_data[] = $current_property->lot;
}
if( ($current_property->unit != NULL) || ($current_property->unit != '') )
{
$property_array_data[] = $current_property->unit;
}
if( ($current_property->street_number != NULL) || ($current_property->street_number != '') )
{
$property_array_data[] = $current_property->street_number;
}
if( ($current_property->po_box != NULL) || ($current_property->po_box != '') )
{
$property_array_data[] = $current_property->po_box;
}
if( ($current_property->street != NULL) || ($current_property->street != '') )
{
$property_array_data[] = $current_property->street;
}
if( ($current_property->street_type_id != NULL) || ($current_property->street_type_id != '') )
{
$get_street_type_data = StreetType::where('id', $current_property->street_type_id)->first();
$property_array_data[] = $get_street_type_data->street_name;
}
if( ($current_property->state_id != NULL) || ($current_property->state_id != '') )
{
$get_state_data = State::where('id', $current_property->state_id)->first();
$property_array_data[] = $get_state_data->state_name;
}
if( ($current_property->suburb_id != NULL) || ($current_property->suburb_id != '') )
{
$get_suburb_data = Suburb::where('id', $current_property->suburb_id)->first();
$property_array_data[] = $get_suburb_data->suburb;
}
if( ($current_property->post_code != NULL) || ($current_property->post_code != '') )
{
$property_array_data[] = $current_property->post_code;
}
$imp_property_data = implode(' ', $property_array_data);
return $imp_property_data;
}
}
当我在搜索框中搜索记录时,我只需要帮助才能搜索上述地址字段..
任何想法 ?
谢谢