zoukankan      html  css  js  c++  java
  • 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' => [

        MewsCaptchaCaptchaServiceProvider::class,

      ],

      'aliases' => [

        'Captcha' => MewsCaptchaFacadesCaptcha::class,

      ],

     

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

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

    视图文件渲染验证码:

     验证验证码:

      public function valite(Request $request){

        $this->validate($request,[

          'title' => "required|captcha"

    ]);

      }

  • 相关阅读:
    IDEA 非常重要的一些设置项 → 一连串的问题差点让我重新用回 Eclipse !
    分布式任务调度平台 → XXL-JOB 实战
    JAVA
    Spring boot
    WebStorm如何去掉参数提示?
    JAVA
    redis tools
    解Bug之路-Nginx 502 Bad Gateway(转发)
    Apache Drill – JDBC Interface & Custom Function
    Apache Drill – Querying Complex Data & Data Definition Statements & Querying Data
  • 原文地址:https://www.cnblogs.com/sheep-fu/p/13355024.html
Copyright © 2011-2022 走看看