Skip to content

Commit 12a2cb4

Browse files
committed
2 parents b8fe9d8 + 5dbf4c1 commit 12a2cb4

File tree

4 files changed

+69
-71
lines changed

4 files changed

+69
-71
lines changed

src/MenuManagerServiceProvider.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MenuManagerServiceProvider extends ServiceProvider
2222
public function boot()
2323
{
2424
// publish migrations
25-
$this->publishes([ __DIR__.'/database/migrations' => database_path('migrations'), ], 'migrations');
25+
$this->publishes([__DIR__.'/database/migrations' => database_path('migrations')], 'migrations');
2626
}
2727

2828
/**
@@ -33,8 +33,7 @@ public function boot()
3333
*/
3434
public function setupRoutes(Router $router)
3535
{
36-
$router->group(['namespace' => 'Backpack\MenuManager\app\Http\Controllers'], function($router)
37-
{
36+
$router->group(['namespace' => 'Backpack\MenuManager\app\Http\Controllers'], function ($router) {
3837
require __DIR__.'/app/Http/routes.php';
3938
});
4039
}
@@ -46,10 +45,10 @@ public function setupRoutes(Router $router)
4645
*/
4746
public function register()
4847
{
49-
$this->app->bind('menumanager',function($app){
48+
$this->app->bind('menumanager', function ($app) {
5049
return new MenuManager($app);
5150
});
5251

5352
$this->setupRoutes($this->app->router);
5453
}
55-
}
54+
}
Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,66 @@
1-
<?php namespace Backpack\MenuManager\app\Http\Controllers\Admin;
1+
<?php
2+
3+
namespace Backpack\MenuManager\app\Http\Controllers\Admin;
24

35
use App\Http\Requests;
4-
use App\Http\Controllers\Controller;
56
use Backpack\CRUD\app\Http\Controllers\CrudController;
6-
use Illuminate\Http\Request;
7-
87
// VALIDATION: change the requests to match your own file names if you need form validation
98
use Backpack\CRUD\app\Http\Requests\CrudRequest as StoreRequest;
109
use Backpack\CRUD\app\Http\Requests\CrudRequest as UpdateRequest;
1110

12-
class MenuItemCrudController extends CrudController {
13-
14-
public function __construct() {
11+
class MenuItemCrudController extends CrudController
12+
{
13+
public function __construct()
14+
{
1515
parent::__construct();
1616

1717
$this->crud->setModel("Backpack\MenuManager\app\Models\MenuItem");
18-
$this->crud->setRoute("admin/menu-item");
19-
$this->crud->setEntityNameStrings("menu item", "menu items");
18+
$this->crud->setRoute('admin/menu-item');
19+
$this->crud->setEntityNameStrings('menu item', 'menu items');
2020

21-
$this->crud->allowAccess('reorder');
22-
$this->crud->enableReorder('name', 1);
21+
$this->crud->allowAccess('reorder');
22+
$this->crud->enableReorder('name', 1);
2323

24-
$this->crud->addColumn([
25-
'name' => 'name',
26-
'label' => "Label"
27-
]);
28-
$this->crud->addColumn([
29-
'label' => "Parent",
30-
'type' => 'select',
31-
'name' => 'parent_id',
32-
'entity' => 'parent',
33-
'attribute' => 'name',
34-
'model' => "\Backpack\MenuManager\app\Models\MenuItem"
35-
]);
24+
$this->crud->addColumn([
25+
'name' => 'name',
26+
'label' => 'Label',
27+
]);
28+
$this->crud->addColumn([
29+
'label' => 'Parent',
30+
'type' => 'select',
31+
'name' => 'parent_id',
32+
'entity' => 'parent',
33+
'attribute' => 'name',
34+
'model' => "\Backpack\MenuManager\app\Models\MenuItem",
35+
]);
3636

37-
$this->crud->addField([
38-
'name' => 'name',
39-
'label' => "Label"
40-
]);
41-
$this->crud->addField([
42-
'label' => "Parent",
43-
'type' => 'select',
44-
'name' => 'parent_id',
45-
'entity' => 'parent',
46-
'attribute' => 'name',
47-
'model' => "\Backpack\MenuManager\app\Models\MenuItem"
48-
]);
49-
$this->crud->addField([
50-
'name' => 'type',
51-
'label' => "Type",
52-
'type' => 'page_or_link',
53-
'page_model' => '\Backpack\PageManager\app\Models\Page'
54-
]);
37+
$this->crud->addField([
38+
'name' => 'name',
39+
'label' => 'Label',
40+
]);
41+
$this->crud->addField([
42+
'label' => 'Parent',
43+
'type' => 'select',
44+
'name' => 'parent_id',
45+
'entity' => 'parent',
46+
'attribute' => 'name',
47+
'model' => "\Backpack\MenuManager\app\Models\MenuItem",
48+
]);
49+
$this->crud->addField([
50+
'name' => 'type',
51+
'label' => 'Type',
52+
'type' => 'page_or_link',
53+
'page_model' => '\Backpack\PageManager\app\Models\Page',
54+
]);
5555
}
5656

57-
public function store(StoreRequest $request)
58-
{
59-
return parent::storeCrud($request);
60-
}
61-
62-
public function update(UpdateRequest $request)
63-
{
64-
return parent::updateCrud($request);
65-
}
57+
public function store(StoreRequest $request)
58+
{
59+
return parent::storeCrud($request);
60+
}
6661

62+
public function update(UpdateRequest $request)
63+
{
64+
return parent::updateCrud($request);
65+
}
6766
}

src/app/Http/routes.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
Route::group(['prefix' => 'admin', 'middleware' => ['web', 'auth'], 'namespace' => 'Admin'], function()
4-
{
5-
CRUD::resource('menu-item', 'MenuItemCrudController');
6-
});
3+
Route::group(['prefix' => 'admin', 'middleware' => ['web', 'auth'], 'namespace' => 'Admin'], function () {
4+
CRUD::resource('menu-item', 'MenuItemCrudController');
5+
});

src/app/Models/MenuItem.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
<?php namespace Backpack\MenuManager\app\Models;
1+
<?php
2+
3+
namespace Backpack\MenuManager\app\Models;
24

35
use Illuminate\Database\Eloquent\Model;
46
use Backpack\CRUD\CrudTrait;
57

6-
class MenuItem extends Model {
7-
8-
use CrudTrait;
8+
class MenuItem extends Model
9+
{
10+
use CrudTrait;
911

10-
protected $table = 'menu_items';
11-
protected $fillable = ['name', 'type', 'link', 'page_id', 'parent_id'];
12+
protected $table = 'menu_items';
13+
protected $fillable = ['name', 'type', 'link', 'page_id', 'parent_id'];
1214

13-
public function parent()
15+
public function parent()
1416
{
1517
return $this->belongsTo('Backpack\MenuManager\app\Models\MenuItem', 'parent_id');
1618
}
@@ -31,10 +33,9 @@ public function page()
3133
*/
3234
public static function getTree()
3335
{
34-
$menu = MenuItem::orderBy('lft')->get();
36+
$menu = self::orderBy('lft')->get();
3537

36-
if ($menu->count())
37-
{
38+
if ($menu->count()) {
3839
foreach ($menu as $k => $menu_item) {
3940
$menu_item->children = collect([]);
4041

@@ -54,7 +55,8 @@ public static function getTree()
5455
return $menu;
5556
}
5657

57-
public function url() {
58+
public function url()
59+
{
5860
switch ($this->type) {
5961
case 'external_link':
6062
return $this->link;
@@ -69,5 +71,4 @@ public function url() {
6971
break;
7072
}
7173
}
72-
7374
}

0 commit comments

Comments
 (0)