PHP code example of ctfang / laravel-watch

1. Go to this page and download the library: Download ctfang/laravel-watch 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/ */

    

ctfang / laravel-watch example snippets




namespace App\Http\Controllers\User;


use Illuminate\Http\Request;

class LoginController
{
    public function login(Request $request)
    {
        // 登陆成功
        return ['request' => $request , 'user_id' => 1];
    }



namespace App\Logics\User;


use Ctfang\LaravelWatch\Context;

class LoginLogic
{
    /**
     * 记录上传参数
     * @param  \Ctfang\LaravelWatch\Context  $context
     * @param  \Closure  $next
     * @return mixed
     */
    public function watchLogin(Context $context, \Closure $next)
    {
        /** @var \Illuminate\Http\Request $request 输入参数获取 */
        $request = $context->getInput('request');

        // 逻辑处理

        // 途径处理完后再登陆
        return $next($context);
    }

    /**
     * 记录登陆日记
     * @param  \Ctfang\LaravelWatch\Context  $context
     * @param  \Closure  $next
     * @return mixed
     */
    public function loginLog(Context $context, \Closure $next)
    {
        // 登陆成功后才记录流失
        $response = $next($context);
        $userId   = $response['user_id'];

        // 记录逻辑
        
        return $response;
    }



namespace App\Http\Controllers\User;


use Illuminate\Http\Request;
use Ctfang\LaravelWatch\Annotations\Watch;
use App\Logics\User\LoginLogic;

class LoginController
{
    /**
     * @Watch(LoginLogic::class,"watchLogin")
     * @Watch(LoginLogic::class,"loginLog")
     */
    public function login(Request $request)
    {
        return ['request' => $request , 'user_id' => 1];
    }