Elegant notes

form validation

Quickly generate

php artisan make:requests LoginRequest

 

public function authorize () 
    { 
        return  true ; 
    } 

    / * * 
     * validation rules for form validation 
     * 
     * @return array 
     * / 
    public function rules () 
    { 
        return [
             ' BrandName ' => ' filled | max: 5 ' ,
             ' ProductCname ' => ' filled | max: 5 | unique: product ' ,
             ' UID ' => ' required | Integer ' 
        ];
    }

The controller call needs to introduce use App \ Http \ Requests \ LoginRequest;

public function login(LoginRequest $request)
    {
        return $this->repo->check($request);
    }

 Project logic

Create a new Repositories folder and create a new LoginRepositories.php file

<?php

namespace App\Repositories;

use Auth;

class LoginRepositories
{
    public function check($request)
    {
        $data = $request->only(['username', 'password']);
        $result = Auth::guard('admin')->attempt($data, $request->get('online'));
        if ($result) {
            return redirect(route('admin.index'));
        }else {
             return redirect (route ( ' admin.login ' ))-> withErrors ([ ' loginerror ' => ' Username and password error ' ]); 
        } 
    } 

}

The controller call introduces use App \ Repositories \ LoginRepositories;

protected $repo;

    public function __construct(LoginRepositories $repo)
    {
        $this->repo = $repo;
    }
public function login(LoginRequest $request)
    {
        return $this->repo->check($request);
    }

 

Guess you like

Origin www.cnblogs.com/linzenews/p/12757603.html