laravel 找不到类 'Illuminate\Support\Facades\Paginator'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40257245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class 'Illuminate\Support\Facades\Paginator' not found
提问by stack
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
找不到类 'Illuminate\Support\Facades\Paginator'
Note:I use Laravel Framework version 5.2.45.
注意:我使用Laravel 框架版本 5.2.45。
How can I fix it?
我该如何解决?
回答by Alexey Mezenin
Try to change it to:
尝试将其更改为:
$results = new \Illuminate\Pagination\Paginator($parameters);
回答by Amit Gupta
Change your this code use Illuminate\Support\Facades\Paginator
to Illuminate\Pagination\Paginator
将此代码更改use Illuminate\Support\Facades\Paginator
为Illuminate\Pagination\Paginator
And hopefully, it will work.
希望它会奏效。