【发布时间】:2018-04-18 16:46:57
【问题描述】:
我想将 URL 从 /topic/{title} 重定向到 /topic/{category}/{title}。 所以我尝试在路线中注册它:
Route::get('/topic/{title}',function(){
return redirect()->action('/topic/{category}/{title}','DetailController@index');
});
但我得到了错误
Action App\Http\Controllers/topic/{category}/{title} 未定义。
有人可以帮我了解路线吗? 感谢您的提前。
这是我的控制器
class DetailController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($section=0,$title = 0)
{
$detail = DB::table('t_artikel')
->join('t_section', 't_section.id_section', '=', 't_artikel.id_section')
//->join('t_kolom', 't_kolom.id', '=', 't_artikel.penalar')
->where('publish', '=', 'Y')
->where('parent_id', '=', 0)
->where('tgl_pub', '<=', date('Y-m-d H:i:s'))
->where('t_artikel.urltitle', '=', $title)
->select('t_artikel.*', 't_section.*', 't_artikel.urltitle as urlartikel')
->first();
$kategori = DB::table('t_section')
->where('id_supsection', '=', 0)
->where('status', '=', 1)
->orderBy('position', 'asc')
->whereNotIn('id_section', [34])
->select('t_section.*')
->get();
$page = 'Detail';
return view ('detail.detail',
['detail' => $detail,
'kategori' => $kategori,
'page' => $page
]);
}
【问题讨论】:
-
拜托,您能与我们分享您的 DetailController@index 中的内容吗?另外,有多少个类别可以有一个主题?是否可能存在 2 个标题相同(但类别不同)的主题?在这种情况下,如果你写 /topic/title 你会期待什么行为?
-
fyi,旧网址已经共享,所以我想将旧网址(主题/mytitle)重定向到我的新网址(主题/mycategory/mytitle)而不共享新网址,如果有用户访问我的旧网址,因此它会自动重定向到新网址。类别和标题是动态的