mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 14:09:43 -08:00
8a6713d5c0
* WIP - beginning of improved requested assets - Use Ajax tables for faster loading - Use new notifications for requesting an asset TODO: - Use ajax tables for requestable asset models - Use new notifications for canceling an asset request - Expire requests once the asset has been checked out to the requesting user * Only show asset name in email if it has one * Refactor requested method to only include non-canceled requests * Refactored requestable assets to log request and cancelation * Added softdeletes on checkout requests * Differentiate between canceling and deleting requests * Added asset request cancelation notification * Added timestamps and corrected unique key on requests table * Improved requests view * Re-use blade for cancel/request email * Refactored BS table formatter for requested assets * Location name min reduced to 2 * Added PAT test as maintenance option This needs to be refactored into database-driven options with a UI * Better slack message * Added getImageUrl method for assets * Include qty in request notifications TODO: - Try to pull requested info from original request for cancelation, otherwise it will default to 1 * Removed old asset request/cancel emails * Added user profile asset request routes * Added profile controller requested assets method * Added blade link to requested assets for profile view * Sort user history desc * Added requested assets blade * Added canceled at to checkoutRequest method * Include qty in request * Fixed comment, removed allowed_columns * Removed Queable methods, since we don’t use a queue * Fixed return type in method doc * Fixed version number * Changed id to user_id for clarity
53 lines
1.1 KiB
PHP
53 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class CheckoutRequest extends Model
|
|
{
|
|
use SoftDeletes;
|
|
protected $fillable = ['user_id'];
|
|
protected $table = 'checkout_requests';
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function requestingUser()
|
|
{
|
|
return $this->user()->first();
|
|
}
|
|
|
|
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()
|
|
{
|
|
if ($this->itemType() == "asset") {
|
|
return $this->itemRequested()->present()->name();
|
|
}
|
|
return $this->itemRequested()->name;
|
|
|
|
}
|
|
}
|