PHP code example of houdunwang / laravel-view

1. Go to this page and download the library: Download houdunwang/laravel-view library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

houdunwang / laravel-view example snippets


php artisan vendor:publish --provider="Houdunwang\Structure\ServiceProvider"

php artisan vendor:publish --provider="Houdunwang\LaravelView\ServiceProvider"

php artisan hd:handle 模型 [目录] [--force]

php artisan hd:handle Category Article

└── CategoryHandle.php  #栏目模型处理器

php artisan hd:handle Category Article --force

public function _title()
{
	return [
		'title'=> '栏目名称',//表单标题
		'type'=> 'input',//表单类型
	];
}

public function _description()
{
	return [
		'title'=> '栏目描述',//表单标题
		'type'=> 'textarea',//表单类型
	];
}

public function _iscommend()
{
	return [
		'title'=> '推荐',//表单标题
		'type'=> 'radio',//表单类型
		'options'=> function () {
            return [
                ['title' => '是', 'value' => 1],
                ['title' => '否', 'value' => 0]
            ];
        },
	];
}

public function _city()
{
	return [
		'title'       => '城市',//表单标题
		'type'        => 'checkbox',//表单类型
		'options'     => function () {
            $values = explode(',', $this->model['city']);
            return [
                ['title' => '北京', 'value' => 1,'checked'=>in_array('北京',$values)],
                ['title' => '上海', 'value' => 2,'checked'=>in_array('上海',$values)],
                ['title' => '广东', 'value' => 3,'checked'=>in_array('广东',$values)],
            ];
        },
	];
}

public function _pic()
{
	return [
		'title'=> '栏目图片',//表单标题
		'type'=> 'image',//表单类型
	];
}

public function _pid()
{
	return [
            'title'       => '父级栏目',//表单标题
            'type'        => 'select',//表单类型
            'options'     => function () {
				$data = [[
				'id'=>0,'title' => '顶级栏目', 'value' => 0, 
				'selected' => false, 'disabled' => false
				]];
				$res=[];
                foreach ($this->model->get() as $cat) {
                    $res[] = [
                        //option文本描述
                        'title'    => $cat['title'],
                        //options值
                        'value'    => $cat['id'],
                        //选中的选项
                        'selected' => $this->model->pid == $cat['id'],
                        //不允许选择自身
                        'disabled' => $this->model->id == $cat['id'],
                    ];
                }
			return $res;
		},
	];
}

public function _title()
{
	return [
		'title'=> '栏目名称',//表单标题
		'type'=> 'input',//表单类型
		'_view'=> 'form.input'//将使用 resources/views/form/input.blade.php 渲染
	];
}

 namespace App\Http\Controllers;

use App\Category;
use App\Tables\CategoryHandle;

class HomeController extends Controller
{
    public function create(Category $Category)
    {
        $handle = new CategoryHandle($Category);
        $html   = $handle->render();

        return view('home', compact('html'));
    }
}