我刚刚在页面上安装了分页,但是当我在页面2上按时,我得到error 404, Page not found
。您知道我的代码有什么问题吗?目前,我限制了6个帖子,并且我需要在第二,第三等页面上显示其余的帖子。
以下是链接:
https://website.com/topic/foreign%20languages/career-solutions?page=2
这是我的路线:
Route::any('/topic/{category?}/career-solutions/{page?}', 'CategoryController@searchCareer' );
这是我的控制人:
public function searchCareer()
{
$data = $this->data;
$c = Input::get ( 'c' );
$d = Input::get ( 'd' );
$category = Category::find($c)->with('event','news','opinion')->firstOrFail();
$q = Input::get ( 'q' );
$user = CareerSolution::where ( 'subject', 'LIKE', '%' . $q . '%' )
->where('career_solutions.topic_category_id', '=', $c)
->join('role_users' , 'role_users.user_id', '=', 'career_solutions.user_id')
->join('roles' , 'roles.id', '=', 'role_users.role_id')
->join('users', 'users.id', '=', 'career_solutions.user_id')
->join('categories', 'categories.id', '=', 'career_solutions.topic_category_id')
->orWhere ( 'career_solutions.user_id', 'LIKE', '%' . $q . '%' )
->orWhere ( 'career_solutions.id', '=', 'events.subject')
->orWhere('career_solutions.topic_category_id' ,'=', $category->id)
->orWhere ( 'career_solutions.user_id', '=', 'users.username')
->select('career_solutions.id as id','subject','users.id as user_id','username', 'profile_picture', 'role_id', 'optional', 'topic_category_id','categories.category')
->paginate(6);
$data['sub_category'] = \App\CareerSolutionCategory::where('parent_id', '=' ,$c)->withCount('career_solution')->get();
$data['test'] = 'view-career-solutions';
$data['link'] = 'search-career-solutions';
$data['type'] = 'Career Solution';
$data['typee'] = 'briefcase fa-';
$topic_id = CareerSolution::select('id', 'subject')
->get();
if (count ( $user ) > 0) {
return view('category-search', $data)
->withDetails($user)
->withQuery($q)
->with(compact('topic_id'))
->with(compact('account'))
->with(compact('category'))
->with(compact('c'))
->with(compact('d'));
} else {
return view('category-search', $data)
->withMessage('No Details found. Try to search again !');
}
}
我的观点:
@foreach($details as $user)
// content
@endforeach
{!! $details->render() !!}
答案 0 :(得分:1)
我认为问题出在Route指令内...您以这种方式声明路由
Route::any('/topic/{category?}/career-solutions/{page?}', 'CategoryController@searchCareer' );
但这对https://website.com/topic/foreign%20languages/career-solutions/2
之类的请求有效,而不对https://website.com/topic/foreign%20languages/career-solutions?page=2
之类的请求有效,因此我认为您应该将路径更改为
Route::any('/topic/{category?}/career-solutions', 'CategoryController@searchCareer' );
如果未设置页面参数,分页将在请求中自动搜索,没有用在路由上声明