Completed
Push — master ( 51084e...d852c9 )
by Yaro
07:57
created

CreateNavigationsTable::up()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 56
rs 8.9599
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
use Illuminate\Database\Schema\Blueprint;
4
use Illuminate\Database\Migrations\Migration;
5
6
class CreateNavigationsTable extends Migration
7
{
8
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        Schema::create('admin_panel_navigation', function (Blueprint $table) {
17
            // These columns are needed for Baum's Nested Set implementation to work.
18
            // Column names may be changed, but they *must* all exist and be modified
19
            // in the model.
20
            // Take a look at the model scaffold comments for details.
21
            // We add indexes on parent_id, lft, rgt columns by default.
22
            $table->increments('id');
23
            $table->integer('parent_id')->nullable()->index();
24
            $table->integer('lft')->nullable()->index();
25
            $table->integer('rgt')->nullable()->index();
26
            $table->integer('depth')->nullable();
27
28
            // Add needed columns here (f.ex: name, slug, path, etc.)
29
            $table->string('name');
30
            $table->string('slug');
31
            $table->string('icon');
32
            $table->boolean('is_active');
33
34
            $table->timestamps();
35
        });
36
37
        $root = new \Yaro\Jarboe\Models\Navigation();
38
        $root->name = 'Root';
39
        $root->slug = '';
40
        $root->is_active = true;
41
        $root->icon = '';
42
        $root->save();
43
44
        $panelNode = \Yaro\Jarboe\Models\Navigation::create([
45
            'name' => 'Admin Panel',
46
            'slug' => 'admin-panel',
47
            'icon' => 'fa-cogs',
48
            'is_active' => true,
49
        ])->makeChildOf($root);
50
51
        \Yaro\Jarboe\Models\Navigation::create([
52
            'name' => 'Admins',
53
            'slug' => 'admin-panel/admins',
54
            'icon' => '',
55
            'is_active' => true,
56
        ])->makeChildOf($panelNode);
57
        \Yaro\Jarboe\Models\Navigation::create([
58
            'name' => 'Roles & Permissions',
59
            'slug' => 'admin-panel/roles-and-permissions',
60
            'icon' => '',
61
            'is_active' => true,
62
        ])->makeChildOf($panelNode);
63
        \Yaro\Jarboe\Models\Navigation::create([
64
            'name' => 'Navigation',
65
            'slug' => 'admin-panel/navigation',
66
            'icon' => '',
67
            'is_active' => true,
68
        ])->makeChildOf($panelNode);
69
    }
70
71
    /**
72
     * Reverse the migrations.
73
     *
74
     * @return void
75
     */
76
    public function down()
77
    {
78
        Schema::drop('admin_panel_navigation');
79
    }
80
81
}
82