PHP code example of seffeng / lumen-basics

1. Go to this page and download the library: Download seffeng/lumen-basics 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/ */

    

seffeng / lumen-basics example snippets


/**
 * TestRequest.php
 * 表单验证示例
 */
namespace App\Http\Requests;

use Seffeng\Basics\Base\FormRequest;
use Seffeng\Basics\Rules\Phone;

class TestRequest extends FormRequest
{
    protected $fillable = ['phone', 'password'];

    public function rules()
    {
        return [
            'phone' => [
                '           'password' => '密码',
        ]);
    }
}

/**
 * TestController.php
 * 表单验证示例 - 控制器
 */
namespace App\Http\Controllers;

use Illuminate\Support\Facades\Validator;
use Seffeng\Basics\Base\Controller;
use Illuminate\Http\Request;
use App\Http\Requests\TestRequest;

class TestController extends Controller
{
    public function index(Request $request)
    {
        $form = new TestRequest();
        $data = $form->load($request->all());
        $validator = Validator::make($data, $form->rules(), $form->messages(), $form->attributes());
        $errors = $form->getErrorItems($validator);
        if ($form->getIsPass()) {
            return $this->responseSuccess($form->getFillItems());
        }
        return $this->responseError($errors['message'], $errors['data']);
    }
}

├─Base                      基础类
│   Controller.php              控制器
│   FormRequest.php             表单验证
│   Model.php                   数据库
│   Response.php                响应
│   Service.php                 服务
├─Constants                 常量定义
│   DeleteConst.php             删除
│   ErrorConst.php              错误
│   StatusConst.php             状态
│   TypeConst.php               类型
├─Exceptions                异常
│   BaseException.php           异常
│   Handler.php                 异常处理器
└─Rules                     验证规则
    Password.php                密码
    Phone.php                   手机号