PHP code example of chinaobject / laravel-pre-request

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

    

chinaobject / laravel-pre-request example snippets


namespace App\Http\FormRequest;

use Chinaobject\PreRequest\PreRequest;

class LoginRequest extends PreRequest
{
    public function rules()
    {
        // the check rules , you can also check the route parameters in this function
        return [
            'username' => 'public function authorize()
    {
        // the authorize check , if you want to check the authorize , you may wirte the logic for yourself.
        return true;
    }
    
    public function assembling()
    {
        // the parameters assembling ,
        // before they were injected to controller,you may wang to assemble the parameters 
        
        // if the request parameters is an array[1,2,3];
        
        $client = ['web','ios','android'];
        
        $data = [];
        foreach($this->data['client'] as $v) {
            $data[] = $client[$v];
        }
        $this->data['client'] = $data;
        
        return $this->data; 
        
        // Ok,you can get the assembled data by $request->fullData() in controller.
        // Of cause , you must inject this FormRequest into your controller.
    }
}