From 7f466ef392bd49e2376a3c3ad7f62d12f0459f36 Mon Sep 17 00:00:00 2001
From: icalF <laser.survivor@gmail.com>
Date: Sun, 3 Apr 2016 00:31:42 +0700
Subject: [PATCH] model lengkap

---
 app/Http/routes.php                           |  4 ---
 app/{Permission.php => Role.php}              |  4 +--
 app/Schedule.php                              | 18 ++++++++++
 app/Tps.php                                   | 13 +++++++
 app/User.php                                  |  9 +++--
 .../2016_03_31_095953_create_users_table.php  |  1 +
 ... 2016_04_01_092434_create_roles_table.php} |  7 ++--
 ...=> 2016_04_02_171120_create_tps_table.php} | 16 ++++-----
 ...016_04_02_172129_create_schedule_table.php | 34 +++++++++++++++++++
 9 files changed, 86 insertions(+), 20 deletions(-)
 rename app/{Permission.php => Role.php} (54%)
 create mode 100644 app/Schedule.php
 create mode 100644 app/Tps.php
 rename database/migrations/{2016_03_31_092434_create_permissions_table.php => 2016_04_01_092434_create_roles_table.php} (72%)
 rename database/migrations/{2016_03_31_092544_create_permission_user_table.php => 2016_04_02_171120_create_tps_table.php} (58%)
 create mode 100644 database/migrations/2016_04_02_172129_create_schedule_table.php

diff --git a/app/Http/routes.php b/app/Http/routes.php
index 808bf88..6ef66fb 100644
--- a/app/Http/routes.php
+++ b/app/Http/routes.php
@@ -11,10 +11,6 @@
 |
 */
 
-Route::get('/', function () {
-    return view('welcome');
-});
-
 Route::group(['middleware' => 'web'], function () {
     Route::auth();
 
diff --git a/app/Permission.php b/app/Role.php
similarity index 54%
rename from app/Permission.php
rename to app/Role.php
index 9442dd1..666c5a0 100644
--- a/app/Permission.php
+++ b/app/Role.php
@@ -4,10 +4,10 @@ namespace App;
 
 use Illuminate\Database\Eloquent\Model;
 
-class Permission extends Model
+class Role extends Model
 {
     public function users()
     {
-        return $this->hasMany('App\User')->withTimestamps();
+        return $this->hasMany('App\User', 'role_id');
     }
 }
diff --git a/app/Schedule.php b/app/Schedule.php
new file mode 100644
index 0000000..434ea30
--- /dev/null
+++ b/app/Schedule.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Schedule extends Model
+{
+    public function users()
+    {
+        return $this->belongsTo('App\User');
+    }
+
+    public function tps()
+    {
+        return $this->belongsTo('App\Tps');
+    }
+}
diff --git a/app/Tps.php b/app/Tps.php
new file mode 100644
index 0000000..6d8825e
--- /dev/null
+++ b/app/Tps.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Tps extends Model
+{
+    public function schedule()
+    {
+        return $this->hasMany('App\Schedule', 'id_tps');
+    }
+}
diff --git a/app/User.php b/app/User.php
index 84be8ee..3fa6df9 100644
--- a/app/User.php
+++ b/app/User.php
@@ -24,8 +24,13 @@ class User extends Authenticatable
         'password', 'remember_token',
     ];
 
-    public function permissions()
+    public function roles()
     {
-        return $this->belongsToMany('App\Permission')->withTimestamps();
+        return $this->belongsTo('App\Role');
+    }
+
+    public function schedule()
+    {
+        return $this->hasMany('App\Schedule', 'id_user');
     }
 }
diff --git a/database/migrations/2016_03_31_095953_create_users_table.php b/database/migrations/2016_03_31_095953_create_users_table.php
index fa960d6..b31ed01 100644
--- a/database/migrations/2016_03_31_095953_create_users_table.php
+++ b/database/migrations/2016_03_31_095953_create_users_table.php
@@ -18,6 +18,7 @@ class CreateUsersTable extends Migration
             $table->string('name');
             $table->string('email')->unique();
             $table->string('password');
+            $table->integer('role_id')->unsigned();
             $table->rememberToken();
             $table->timestamps();
         }); 
diff --git a/database/migrations/2016_03_31_092434_create_permissions_table.php b/database/migrations/2016_04_01_092434_create_roles_table.php
similarity index 72%
rename from database/migrations/2016_03_31_092434_create_permissions_table.php
rename to database/migrations/2016_04_01_092434_create_roles_table.php
index 84023a5..0b22c92 100644
--- a/database/migrations/2016_03_31_092434_create_permissions_table.php
+++ b/database/migrations/2016_04_01_092434_create_roles_table.php
@@ -3,7 +3,7 @@
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Database\Migrations\Migration;
 
-class CreatePermissionsTable extends Migration 
+class CreateRolesTable extends Migration 
 {
     /**
      * Run the migrations.
@@ -12,11 +12,10 @@ class CreatePermissionsTable extends Migration
      */
     public function up()
     {
-        Schema::create('permissions', function(Blueprint $table)
+        Schema::create('roles', function(Blueprint $table)
         {
             $table->increments('id');
             $table->string('name');
-            $table->string('slug')->unique();
             $table->text('description')->nullable();
             $table->timestamps();
         });
@@ -29,6 +28,6 @@ class CreatePermissionsTable extends Migration
      */
     public function down()
     {
-        Schema::drop('permissions');
+        Schema::drop('roles');
     }
 }
\ No newline at end of file
diff --git a/database/migrations/2016_03_31_092544_create_permission_user_table.php b/database/migrations/2016_04_02_171120_create_tps_table.php
similarity index 58%
rename from database/migrations/2016_03_31_092544_create_permission_user_table.php
rename to database/migrations/2016_04_02_171120_create_tps_table.php
index 099f1c9..7306c9c 100644
--- a/database/migrations/2016_03_31_092544_create_permission_user_table.php
+++ b/database/migrations/2016_04_02_171120_create_tps_table.php
@@ -3,7 +3,7 @@
 use Illuminate\Database\Schema\Blueprint;
 use Illuminate\Database\Migrations\Migration;
 
-class CreatePermissionUserTable extends Migration 
+class CreateTpsTable extends Migration
 {
     /**
      * Run the migrations.
@@ -12,13 +12,14 @@ class CreatePermissionUserTable extends Migration
      */
     public function up()
     {
-        Schema::create('permission_user', function(Blueprint $table)
+        Schema::create('tps', function(Blueprint $table)
         {
             $table->increments('id');
-            $table->integer('permission_id');
-            $table->integer('user_id');
+            $table->integer('capacity_now');
+            $table->integer('capacity_full');
+            $table->integer('manager_id')->unsigned();
             $table->timestamps();
-        });
+        }); 
     }
 
     /**
@@ -28,7 +29,6 @@ class CreatePermissionUserTable extends Migration
      */
     public function down()
     {
-        Schema::drop('permission_user');
+        Schema::drop('tps');
     }
-
-}
\ No newline at end of file
+}
diff --git a/database/migrations/2016_04_02_172129_create_schedule_table.php b/database/migrations/2016_04_02_172129_create_schedule_table.php
new file mode 100644
index 0000000..d45e5c1
--- /dev/null
+++ b/database/migrations/2016_04_02_172129_create_schedule_table.php
@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateScheduleTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('schedule', function(Blueprint $table)
+        {
+            $table->increments('id');
+            $table->integer('id_tps')->unsigned();
+            $table->integer('id_user')->unsigned();
+            $table->timestamp('time');
+            $table->timestamps();
+        }); 
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('schedule');
+    }
+}
-- 
GitLab