<?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 (占了很多地方不好意思)