mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-26 22:19:41 -08:00
2d8269ddcd
* Create a new action_log table to replace asset_log. Use Polymorphism to generalize class and targets. Port everything I can find to use it. Add a migration to port the asset_logs table to action_logs. * Initial work on requestable asset models * Backend work for polymorphic requests table to store checkout requests. * Add missing files * Add a record to the db when requesting items. Build up a testing route for interfacing with this. * Users can now toggle requests of items on the request page. Reformat page to use the same tab layout we use elsewhere * Polymorphic request function. Implement requesting of asset models. Need to port mail/slack to notifications still. * Implement requesting of asset models. Build up emails and notifications to support it. Allow specifying a quantity of model to request. * Add view to show currently requested assets. Needs some work and cleanup, but it isn't accessible from anywhere yet.
46 lines
973 B
PHP
46 lines
973 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\CheckoutRequest;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
// $asset->requests
|
|
// $asset->isRequestedBy($user)
|
|
// $asset->whereRequestedBy($user)
|
|
trait Requestable
|
|
{
|
|
|
|
public function requests()
|
|
{
|
|
return $this->morphMany(CheckoutRequest::class, 'requestable');
|
|
}
|
|
|
|
public function isRequestedBy(User $user)
|
|
{
|
|
return $this->requests()
|
|
->where('user_id', $user->id)
|
|
->exists();
|
|
}
|
|
|
|
public function scopeRequestedBy($query, User $user)
|
|
{
|
|
return $query->whereHas('requests', function ($query) use ($user) {
|
|
$query->where('user_id', $user->id);
|
|
});
|
|
}
|
|
|
|
public function request()
|
|
{
|
|
$this->requests()->save(
|
|
new CheckoutRequest(['user_id' => Auth::id()])
|
|
);
|
|
}
|
|
|
|
public function cancelRequest()
|
|
{
|
|
$this->requests()->where('user_id', Auth::id())->delete();
|
|
}
|
|
}
|