PHP code example of eusonlito / laravel-processor

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

    

eusonlito / laravel-processor example snippets


namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;
use Eusonlito\LaravelProcessor\Controllers\ProcessorTrait;

abstract class Controller extends BaseController
{
    use ProcessorTrait;
}

namespace App\Http\Controllers;

class Users extends Controller
{
    public function login()
    {
        // https://github.com/oscarotero/form-manager
        $form = new Forms\Users\Login();

        if (is_object($processor = $this->processor(__FUNCTION__, $form))) {
            return $processor;
        }

        // https://github.com/eusonlito/laravel-Meta
        // https://github.com/oscarotero/Gettext
        Meta::meta('title', __('Login as User'));

        return view('web.pages.users.login', [
            'form' => $form,
        ]);
    }
}

namespace App\Http\Controllers\Forms\Users;

use FormManager\Builder as B;
use FormManager\Containers\Form as F;

class Login extends F
{
    public function __construct()
    {
        return $this->method('post')->add([
            '_processor' => B::hidden()->val('login'),

            'user' => B::text()->attr([
                'placeholder' => __('Your user'),
                'autofocus' => true,
                '

namespace App\Http\Processors;

use Eusonlito\LaravelProcessor\Processors\ProcessorTrait;

abstract Processor
{
    use ProcessorTrait;
}

namespace App\Http\Processors;

use Exception;
use Auth;
use Hash;
use Redirect;
use Request;
use App\Models;

class Users extends Processor
{
    public function login($form)
    {
        // Check if is a valid request to execute this function
        // Also, validate $form
        if (!($data = $this->check(__FUNCTION__, $form))) {
            return $data;
        }

        $success = Auth::attempt([
            'user' => $data['user'],
            'password' => $data['password'],
        ], $data['remember']);

        if ($success !== true) {
            Models\UserSession::create([
                'user' => $data['user'],
                'ip' => Request::getClientIp(),
                'success' => 0,
            ]);

            throw new Exception(__('Incorrect user or password'));
        }

        Models\UserSession::create([
            'user' => $data['user'],
            'ip' => Request::getClientIp(),
            'success' => 1,
            'users_id' => Auth::user()->id,
        ]);

        return Redirect::back();
    }
}

@if ($flash = Session::get('flash-message'))