Class' Illuminate \ Support \ Facades \ Paginator'未找到

时间:2016-10-26 08:26:28

标签: php laravel pagination laravel-5.2

这是我的代码:

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Paginator;
use Illuminate\Support\Facades\Input;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\news;
use App\productions;

class SearchController extends Controller
{
    public function index(Request $request){
        $q = $request->q;
        $page = Input::get('page', 1);
        $paginate = 5;

        $first = DB::table('news')
            ->select(['id', 'title', 'description', 'imgPath'])
            ->where(function($query) use ($q) {
                $query->where('title', 'like', "%$q")
                    ->orWhere('description', 'like', "%$q");
            });

        $result = DB::table('productions')
            ->select(['id', 'title', 'description', 'imgPath'])
            ->where(function($query) use ($q) {
                $query->where('title', 'like', "%$q")
                    ->orWhere('description', 'like', "%$q");
            })
            ->unionAll($first)
            ->get();

        $slice = array_slice($result, $paginate * ($page - 1), $paginate);
        $results = Paginator::make($slice, count($result), $paginate);


        return view('search', compact('results'));
    }
}

当我运行它时,会抛出此错误:

  

Class' Illuminate \ Support \ Facades \ Paginator'找不到

注意:我使用 Laravel Framework版本5.2.45

我该如何解决?

2 个答案:

答案 0 :(得分:3)

尝试将其更改为:

$results = new \Illuminate\Pagination\Paginator($parameters);

答案 1 :(得分:3)

将此代码use Illuminate\Support\Facades\Paginator更改为Illuminate\Pagination\Paginator

希望它会起作用。