4
votes

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?

2
There is no Pagination Facade, check out the documentation laravel.com/docs/5.2/paginationMina Abadir

2 Answers

5
votes

Try to change it to:

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

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

And hopefully, it will work.