From 54bad2e4f6099e59cb658c1eadc9c06ca3dd65e2 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Feb 2015 03:19:45 -0800 Subject: [PATCH] More accessory relationships --- app/controllers/admin/AccessoriesController.php | 5 +++-- .../2015_02_26_091228_add_accessories_user_table.php | 3 ++- app/models/Accessory.php | 6 ++++++ app/models/User.php | 5 +++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/AccessoriesController.php b/app/controllers/admin/AccessoriesController.php index fe3a687a0f..cf83593a34 100755 --- a/app/controllers/admin/AccessoriesController.php +++ b/app/controllers/admin/AccessoriesController.php @@ -11,6 +11,7 @@ use Sentry; use Str; use Validator; use View; +use User; class AccessoriesController extends AdminController { @@ -265,7 +266,7 @@ class AccessoriesController extends AdminController $logaction = new Actionlog(); $logaction->accessory_id = $accessory->id; $logaction->checkedout_to = $accessory->assigned_to; - $logaction->accessory_type = 'hardware'; + $logaction->accessory_type = 'accessory'; $logaction->location_id = $user->location_id; $logaction->user_id = Sentry::getUser()->id; $logaction->note = e(Input::get('note')); @@ -278,7 +279,7 @@ class AccessoriesController extends AdminController if ($accessory->requireAcceptance()=='1') { - Mail::send('emails.accept-accessory', $data, function ($m) use ($user) { + Mail::send('emails.accept-asset', $data, function ($m) use ($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); $m->subject('Confirm accessory delivery'); }); diff --git a/app/database/migrations/2015_02_26_091228_add_accessories_user_table.php b/app/database/migrations/2015_02_26_091228_add_accessories_user_table.php index d2b6fe2fc1..e8a01d5508 100644 --- a/app/database/migrations/2015_02_26_091228_add_accessories_user_table.php +++ b/app/database/migrations/2015_02_26_091228_add_accessories_user_table.php @@ -15,7 +15,8 @@ class AddAccessoriesUserTable extends Migration { // Schema::create('accessories_users', function ($table) { $table->increments('id'); - $table->integer('user_id')->nullable()->default(NULL); + $table->integer('user_id')->nullable()->default(NULL); + $table->integer('accessory_id')->nullable()->default(NULL); $table->integer('assigned_to')->nullable()->default(NULL); $table->timestamps(); }); diff --git a/app/models/Accessory.php b/app/models/Accessory.php index ed81391777..34a3d8240e 100755 --- a/app/models/Accessory.php +++ b/app/models/Accessory.php @@ -29,4 +29,10 @@ class Accessory extends Elegant } + public function users() + { + return $this->belongsToMany('User', 'users', 'id')->withTrashed(); + } + + } diff --git a/app/models/User.php b/app/models/User.php index c36727e5df..e5ccea5a99 100755 --- a/app/models/User.php +++ b/app/models/User.php @@ -42,6 +42,11 @@ class User extends SentryUserModel { return $this->hasMany('Asset', 'assigned_to')->withTrashed(); } + + public function accessories() + { + return $this->belongsToMany('Accessories', 'accessories_users', 'assigned_to')->withTrashed(); + } public function licenses() {