Php Laravel-嵌套uri获取父对象的父对象(等…)
我正在尝试创建一个带有嵌套child的uri(使用laravel框架) 我的问题是,我当前的代码只检索子级的上述父级。而不是该父级之上的父级(如果存在)等等 (我的数据库表有一列“parent”,其中包含上述父级的id) 有人能帮我解决这个问题吗 我的代码:Php Laravel-嵌套uri获取父对象的父对象(等…),php,laravel,Php,Laravel,我正在尝试创建一个带有嵌套child的uri(使用laravel框架) 我的问题是,我当前的代码只检索子级的上述父级。而不是该父级之上的父级(如果存在)等等 (我的数据库表有一列“parent”,其中包含上述父级的id) 有人能帮我解决这个问题吗 我的代码: $pageRoutes = array(); foreach ($pages as $page) { $pageRoutes[] = self::PageRoute($page->
$pageRoutes = array();
foreach ($pages as $page) {
$pageRoutes[] = self::PageRoute($page->id, $page->parent, $page->uri, $searchTerm);
}
我正在调用的函数:
public function PageRoute($pageId, $parent, $prevUri = null, $searchTerm = false)
{
if (isset($parent) && $parent == null)
$pages = DB::table('tblpages')
->select('tblpages.id','tblpages.uri')
->whereNull('tblpages.parent')
->where('tblpages.is_active', '=', true)
->get();
else
$pages = DB::table('tblpages')
->select('tblpages.id', 'tblpages.uri', 'tblpages.parent')
->where('tblpages.parent', '=', $pageId)
->where('tblpages.name', 'LIKE', $searchTerm)
->where('tblpages.is_active', '=', true)
->get();
$path = array();
foreach ($pages as $page)
{
if ($page->uri != '/')
$page->uri = $prevUri.'/'.$page->uri;
$path[$page->id] = $page;
$path = self::PageRoute($page->id, $page->uri, $prevUri) + $path;
}
return $path;
}
提前谢谢你 有什么理由可以使用
我检索的uri是单个的,所以它们已经是部分的了。所以我想把它们粘在一起:到目前为止,我只能用(而不是用)来做这件事
Request::segment(1) // "first"
Request::segment(2) // "second"
Request::segment(3) // "third"