2016-09-15 19:58:27 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2016-09-15 19:58:27 -07:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-03-13 20:12:03 -07:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2016-09-15 19:58:27 -07:00
|
|
|
|
|
|
|
class CheckoutRequest extends Model
|
|
|
|
{
|
2018-04-04 17:33:02 -07:00
|
|
|
use SoftDeletes;
|
2024-09-17 14:16:41 -07:00
|
|
|
protected $fillable = ['created_by'];
|
2016-09-15 19:58:27 -07:00
|
|
|
protected $table = 'checkout_requests';
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requestingUser()
|
|
|
|
{
|
2023-07-10 15:34:00 -07:00
|
|
|
return $this->user()->withTrashed()->first();
|
2016-09-15 19:58:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function requestedItem()
|
|
|
|
{
|
|
|
|
return $this->morphTo('requestable');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function itemRequested() // Workaround for laravel polymorphic issue that's not being solved :(
|
|
|
|
{
|
|
|
|
return $this->requestedItem()->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function itemType()
|
|
|
|
{
|
|
|
|
return snake_case(class_basename($this->requestable_type));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function location()
|
|
|
|
{
|
|
|
|
return $this->itemRequested()->location;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function name()
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
if ($this->itemType() == 'asset') {
|
2016-12-23 17:52:00 -08:00
|
|
|
return $this->itemRequested()->present()->name();
|
2016-09-15 19:58:27 -07:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
return $this->itemRequested()->name;
|
2016-09-15 19:58:27 -07:00
|
|
|
}
|
|
|
|
}
|