Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'Illuminate\Support\Facades\Paginator' not found

Here is my code:

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'));
    }
}

When I run it, it throws this error:

Class 'Illuminate\Support\Facades\Paginator' not found

Note: I use Laravel Framework version 5.2.45.

How can I fix it?

like image 649
stack Avatar asked Dec 24 '22 00:12

stack


2 Answers

Change your this code use Illuminate\Support\Facades\Paginator to Illuminate\Pagination\Paginator

And hopefully, it will work.

like image 165
Amit Gupta Avatar answered Dec 26 '22 17:12

Amit Gupta


Try to change it to:

$results = new \Illuminate\Pagination\Paginator($parameters);
like image 31
Alexey Mezenin Avatar answered Dec 26 '22 15:12

Alexey Mezenin