Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
4b5664af
Commit
4b5664af
authored
Oct 13, 2016
by
庄欣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分类修改
parent
bf56583b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
6 deletions
+31
-6
app/Cates/Controller/Category.php
+29
-4
routes/api.php
+2
-2
No files found.
app/Cates/Controller/Category.php
View file @
4b5664af
...
...
@@ -22,16 +22,41 @@ class Category extends \Illuminate\Routing\Controller
$model
=
$this
->
setBlurSearch
(
CategoryModel
::
class
,
$where
,
"category_name"
);
is_null
(
$where
)
&&
$where
=
[];
$row
=
isset
(
$query
[
"size"
])
?
$query
[
"size"
]
:
config
(
"app.default_perpage"
);
return
Response
::
success
(
$model
->
paginate
(
$row
)
->
toArray
());
return
Response
::
success
(
$model
->
where
(
'is_del'
,
0
)
->
paginate
(
$row
)
->
toArray
());
}
public
function
info
(
$id
)
public
function
child
(
$id
)
{
$data
=
CategoryModel
::
where
(
'is_del'
,
0
)
->
where
(
'previous'
,
$id
)
->
get
()
->
toArray
();
return
Response
::
success
(
$data
);
}
public
function
child
(
$id
)
public
function
pretty
(
)
{
$data
=
CategoryModel
::
where
(
'is_del'
,
0
)
->
get
()
->
toArray
();
$data
=
$this
->
list_to_tree
(
$data
,
"id"
,
"previous"
);
return
Response
::
success
(
$data
);
}
protected
function
list_to_tree
(
$list
,
$pk
=
'id'
,
$pid
=
'pid'
,
$child
=
'child'
,
$root
=
0
)
{
$tree
=
array
();
if
(
is_array
(
$list
))
{
$refer
=
array
();
foreach
(
$list
as
$key
=>
$data
)
{
$refer
[
$data
[
$pk
]]
=&
$list
[
$key
];
}
foreach
(
$list
as
$key
=>
$data
)
{
$parentId
=
$data
[
$pid
];
if
(
$root
==
$parentId
)
{
$tree
[]
=&
$list
[
$key
];
}
else
{
if
(
isset
(
$refer
[
$parentId
]))
{
$parent
=&
$refer
[
$parentId
];
$parent
[
$child
][]
=&
$list
[
$key
];
}
}
}
}
return
$tree
;
}
}
routes/api.php
View file @
4b5664af
...
...
@@ -29,9 +29,9 @@ Route::group(["prefix" => "cates", 'namespace' => Provider::getNamespace("cates"
//获取所有分类
Route
::
get
(
"/"
,
"Category@index"
);
//获取子分类
//
Route::get ("/{id}/child" , "Category@child")->where(['id' => '\d+']) ;
Route
::
get
(
"/
{
id
}
/child"
,
"Category@child"
)
->
where
([
'id'
=>
'\d+'
])
;
//分类详情
// Route::get ("/{id}$", "Category@info
");
Route
::
get
(
"/pretty"
,
"Category@pretty
"
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment