一.房源属性表设计
房源属性是对一个房源的信息的补充和描述,在日后的展示和数据调用检索中都有着重要的条件依据。如下图所示,框选区域为房源的属性
1.创建房源属性和对应的迁移文件
php artisan make:model Models/Fangattr -m
2.迁移文件代码
Schema::create('fangattrs', function (Blueprint $table) {
// 主键
$table->bigIncrements('id');
$table->unsignedInteger('pid')->default(0)->comment('上级ID');
$table->string('field_name',50)->default('')->comment('字段名');
$table->string('name',50)->default('')->comment('属性名称');
$table->string('icon',200)->default('')->comment('图标');
$table->timestamps();
// 软删除
$table->softDeletes();
});
3.执行迁移生成对应的数据表
php artisan migrate
二.房源属性列表
1.创建对应资源控制器和资源路由
php artisan make:controller Admin/FangAttrController -r -m Models/Fangattr
Route::resource('fangattr','FangAttrController ',['as'=>'admin']);
资源路由==普通路由
//文件上传
Route::post('fangattr/upfile','FangAttrController@upfile')->name('admin.fangattr.upfile');
//展示页面
Route::get('fangattr/index','FangAttrController@index')->name('admin.fangattr.index');
//添加页面
Route::get('fangattr/create','FangAttrController@create')->name('admin.fangattr.create');
//添加
Route::post('fangattr/store','FangAttrController@store')->name('admin.fangattr.store');
//删除
Route::get('fangattr/del/{id}','FangAttrController@destroy')->name('admin.fangattr.destroy');
//软删除还原
Route::get('fangattr/restore/{id}','FangAttrController@restore')->name('admin.fangattr.restore');
//修改页面
Route::get('fangattr/edit/{id}','FangAttrController@edit')->name('admin.fangattr.edit');
//修改
Route::put('fangattr/edit/{id}','FangAttrController@update')->name('admin.fangattr.update');
2.准备页面
@extends('admin.common.main_app')
@section('css')
@endsection
@section('cnt')
<nav class="breadcrumb">
<i class="Hui-iconfont"></i> 首页
<span class="c-gray en">></span> 房源属性管理
<span class="c-gray en">></span> 房源属性列表
<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
<i class="Hui-iconfont"></i>
</a>
</nav>
<div class="page-container">
<form method="get" class="text-c"> 输入你想要搜索的权限名称:
<input type="text" name="username" class="input-text" style="width:120px;">
<button type="submit" class="btn btn-success radius" id="" name="">
<i class="Hui-iconfont"></i> 搜节点
</button>
</form>
<div class="cl pd-5 bg-1 bk-gray mt-20">
<span class="l">
<a href="{
{route('admin.fangattr.create')}}" class="btn btn-primary radius"><i class="Hui-iconfont"></i> 添加房源属性</a>
</span>
<span class="r">共有数据:<strong>88</strong> 条</span>
</div>
@include('admin.common.validate')
@include('admin.common.msg')
<div class="mt-20">
<table class="table table-border table-bordered table-hover table-bg table-sort">
<thead>
<tr class="text-c">
<th width="80">ID</th>
<th width="80">房源属性名称</th>
<th width="80">图标</th>
<th width="80">字段名称</th>