laravel框架之分页&&上传图片

分页:

   public function r(){
       $list=DB::table('pl')->paginate(2);
       return view('fy/r',['list'=>$list]);
    }
注:paginate(几条为一页)
在试图里定义:

分页字符串:{{$list->render()}}
总条数:{{$list->total()}}
点击显示当前页数:{{$list->currentpage()}}


css样式:<link rel="stylesheet" type="text/css" href="{{asset('css')}}/app.css">
文字样式在:blog\laravel\framework\src\lluminate\pagination\resours\riew

上传图片:

一定要在form后加上 "enctype"
 <form action="{{url('/fileadd')}}" method="post" enctype="multipart/form-data">

模型里具体代码实现:


  public function add($post){
        //图片操作
       $file = request()->file('file');//通过request()方法获取上传过来的图片
        $hz=$file->getClientOriginalExtension();//获取图片后缀
        $newname=date("YmdHis").rand(111,999).'.'.$hz;//拼接新的图片名字
        $date['file']=$path;
        $date['filename']=$post['filename'];
        $date['addrries']=$post['addrries'];
        $date['px']=$post['px'];
        $sql=DB::table('file1')->insert($date);
        if($sql)
        {
           $status['status']=200;
        }
        else{
            $status['status']=201;
        };
            return $status;
    }

猜你喜欢

转载自blog.csdn.net/qq_43572631/article/details/83996420