laravel数据库和cookie和验证码

数据库查询:   
     //排序和限制每一页显示的条数和从那一条开始
    //    $iok= DB::table('product')->orderBy('id','desc')->limit(5)->offset(2)->get();
    //    var_dump($iok);
      /**把数据渲染到视图文件中,如果视图文件是xxx.blade.php的话页面中就可以{{}}用这个来渲染,否则就用php原生写法<?php echo'$title'?>*/
      //方法一
    //   $title='标题';
    //   $arr=['a',1,'b'];
      //$res=compact('title','arr');
      //return view('welcome',$res);
      //方法二
      //return view('welcome',['title'=>'标题']);
     //方法三
    //   return view('welcome')->with('title',$iok);
    //数据传到页面用@foreach循环输出,如果视图文件是xxx.blade.php的话页面中就可以{{}}用这个来渲染,否则就用php原生写法
      $iok= DB::table('product')->orderBy('id','desc')->get();
      return view('welcome')->with('title',$iok);
cookie:
      //登陆
      if($request->isMethod('post')){
        $where['uname']=trim($request->input('uname'));
        $where['pasd']=md5($request->input('pasd'));
        $info=db::table('admin')->where($where)->first();
        //判断有没有查出
        if($info){
          //存储cookie
          Cookie::queue('admin',$info->id);
          //跳转
          return redirect('/user/user');
        }

      }
 
//获取cookie
        var_dump(Cookie::get('admin'));
//判断没有cookie就返回登陆页面 这个是写在初始化函数里面
if(!Cookie::has('admin')){
  redirenct('/admin/login')->send
}
验证码:

composer require mews/captcha 用这个下载

 

 修改配置config/app.php

  'providers' => [

    Mews\Captcha\CaptchaServiceProvider::class,

  ],

  'aliases' => [

    'Captcha' => Mews\Captcha\Facades\Captcha::class,

  ],

 

如果想用自己配置文件可以  

php artisan vendor:publish 选择生成自己的config/captcha.php

视图文件渲染验证码:

 

 

 验证验证码:

  public function valite(Request $request){

    $this->validate($request,[

      'title' => "required|captcha"

]);

  }

 

posted @ 2020-07-21 14:50  不吃肉的羊  阅读(176)  评论(0编辑  收藏  举报