stack stack - 1 month ago 14
PHP Question

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?

Answer

Try to change it to:

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