戴草帽的小白

108 经验值

<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;

//引入核心控制器
use App\Http\Controllers\Controller;

//引入自定义表单验证类
use App\Http\Requests\CheckPublicPost;
use Validator;
//引入admin模型
use App\Http\Models\Admin;

//引入验证码类(laravel没有封装验证码,需要自己引入)
require 'resources/org/code/Code.class.php';

class PublicController extends Controller
{

//载入视图
public function login(){
    //调用显示视图
    return view('public.login');
}

//生成验证码
public function code(){
    //实例化验证码类
    $code = new \Code();
    //生成验证码
    $code->make();
}

//登录
public function check(CheckPublicPost $request){
    //表单验证已经完成,验证成功后自动向下执行
    $data = $request->all();
    //$data = $request->input('admin');
    //$data['password'] = md5($data['password']);
    //$admin = Admin::where($data)->first();
    dd($data);die;
    if($admin){
        //用户信息存储到session中
        session(['admin'=>$admin]);
        //跳转到index(首页)
        return redirect('admin/index')->with('success','添加成功!');
    }else{
        return back()->with('error','用户名或密码错误!');
    }
}

} 这是controller (占了很多地方不好意思)

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class CheckPublicPost extends Request
{

/**
  • Determine if the user is authorized to make this request.
    *

  • @return bool
    */

    public function authorize()
    {

    return true;

    }
    
    /**
  • Get the validation rules that apply to the request.
    *

  • @return array
    */

    public function rules()
    {

    return [

       'username' => 'bail|require|unique:posts|between:6,20',
       'password' => 'bail|require|between:6,14',

    ];

    }
    
    
    /**
  • @Author tst

  • @DateTime 2018-01-21

  • @version 1.0

  • 自定义错误消息
    */

    public function messages(){

    return [

       'username.require' => '用户名不能为空',
       'username.unique' => '用户名已存在',
       'username.between' => '用户名在6-20个字符之间',
       'password.require' => '密码不能为空',
       'password.between' => '密码长度在6-14个字符之间',

    ];

    }

    } 这是formrequest

评论发不了图片 老师能帮我看一下么

BadMethodCallException in Validator.php line 3295:
Method [validateRequire] does not exist.
in Validator.php line 3295
at Validator->__call('validateRequire', array('username', 'admin', array(), object(Validator))) in Validator.php line 485
at Validator->validateRequire('username', 'admin', array(), object(Validator)) in Validator.php line 485
at Validator->validate('username', 'require') in Validator.php line 425
at Validator->passes() in ValidatesWhenResolvedTrait.php line 24
at FormRequest->validate() in FoundationServiceProvider.php line 41 这是什么问题?是要引入哪个文件么?