PHP code example of liuchang103 / hyperf-store

1. Go to this page and download the library: Download liuchang103/hyperf-store 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/ */

    

liuchang103 / hyperf-store example snippets


namespace App\Repository;

use App\Model\Admin;
use App\Server\Message;

class AdminRepository extends \HyperfStore\Repository
{
    public $message;

    // 注入消息依赖
    public function __construct(Message $message)
    {
        $this->message = $message;
    }

    // 放入模型
    public function build()
    {
        return new Admin;
    }

    // 禁止登陆
    public function close()
    {
        $this->model->close = false;
        $this->model->save();

        // 发送消息
        $this->message->send('close');
    }
}

// 新建 or 更新用户
$admin->save([
    'username' => 'admin',
    'password' => 'admin
]);

$admin->exception(function() use($admin){
    $admin->save([
        'username' => 'admin',
        'password' => 'admin
    ]);
});

$adminAll = Admin::get();

$admin->modelMap($adminAll, function() {
    
    // 关闭所有
    $this->close();
})

class AdminQuery extends \HyperfStore\Query
{
    // 自定义处理条件 
    protected static function queryTime($model, $data)
    {
        $time = expload('-', $data);

        return $model->where('start_time', '>', $time[0])
            ->where('end_time', '<', $time[1]);
    }
}

AdminQuery::query(
    AdminQuery::model(),
    [ 'time' => '2020/02/02-2020/03/03' ]
);

Route::middleware('auth')->group(function(){
    Route::get('/', 'IndexController@index');
    Route::get('/user', 'IndexController@user');
});

Route::middleware('auth')->group(__DIR__ . '/auth.php');

// auth.php

Route::get('/', 'IndexController@index');
Route::get('/user', 'IndexController@user');

Route::namespace('App\Controller')->group(function(){
    Route::get('/', 'IndexController@index');

    Route::namespace('User')->middleware('auth')->group(function(){
        
        Route::get('/user', 'IndexController@index');
    });
});

Route::namespace('User')->prefix('/user')->group(function(){
    Route::get('/', 'IndexController@index');
});