mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
987536930c
* Fix some n+1 problems * Use route in notification dropdown to make sure we link to correct page * Work on better UI support for checkout to non-user. Fix links on index bootstrap table, work towards eliminating assignedUser * Remove Asset::assigneduser() relationship. Instead add a checkedOutToUser() method and/or port to using assignedTo() * Adjust string to fit new reality * Fix #3780. Move the consumables getDataView method to the ApiController. Not entirely RESTful, but it's a weird method that probably doesn't need its own controller and the functionality would be strange to stack on the userscontroller... * Fix file uploads to assets and restore the delete route. * Add asset maintence edit action to index. * Suppliers asset list should link to the related asset, not to the supplier with same ID. * Asset models page should use polymorphic formatter on assigned to to better handle assorted item types. * Comment out more assigneduser fallacy until we figure out the query builder approach to searching for location text.
46 lines
980 B
PHP
46 lines
980 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)
|
|
{
|
|
$requests = $this->requests->where('user_id', $user->id);
|
|
|
|
return $requests->count() > 0;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|