app/Http/Controllers/admin/CatesController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index(Request $request)
    {
        $count = DB::table('jc_cates')->whereNull('deleted_at')->count();
        if($request->has('search')){
            $search = $request->input('search');
            $cates = Cates::where('classname','like','%'.$search.'%')->paginate(5)->appends($request->input());
            $count = count($cates);
            return view('admin.cates.index',['title'=>'分类列表','cates'=>$cates,'count'=>$count]);
        }else{
            $cates = Cates::select('id','pid','classname','path','status',DB::raw("concat(path,',',id) as paths"))->orderBy('paths','asc')->paginate(5);
            foreach($cates as $k=>$v){
                $i = substr_count($v->path,',');
                $v->classname = str_repeat('|----',$i).$v->classname; 
            }
            return view('admin.cates.index',['title'=>'分类列表','cates'=>$cates,'count'=>$count]);
        }
    }
public function index ( Request $ request ) { $ count = DB :: table ( 'jc_cates' ) -> whereNull ( 'deleted_at' ) -> count ( ) ; if ( $ request -> has ( 'search' ) ) { $ search = $ request -> input ( 'search' ) ; $ cates = Cates :: where ( 'classname' , 'like' , '%' . $ search . '%' ) -> paginate ( 5 ) -> appends ( $ request -> input ( ) ) ; $ count = count ( $ cates ) ; return view ( 'admin.cates.index' , [ 'title' => '分类列表','cates' = >$cates ,' c ount' = >$count ]) ; } else { $ cates = Cates :: select ( 'id' , 'pid' , 'classname' , 'path' , 'status' , DB :: raw ( " concat(path,',',id) as paths " ) ) -> orderBy ( 'paths' , 'asc' ) -> paginate ( 5 ) ; foreach ( $ cates as $ k => $ v ) { $ i = substr_count ( $ v -> path , ',' ) ; $ v -> classname = str_repeat ( '|----' , $ i ) . $ v -> classname ; } return view ( 'admin.cates.index' , [ 'title' => '分类列表','cates' = >$cates ,' c ount' = >$count ]) ; } }
Display a listing of the resource.
Display a listing of the resource .
// dump($cates); //设置计算数据表中所有信息的数量 //统计逗号出现的次数 //拼接|--