2015-10-28 21:22:07 +02:00
|
|
|
<?php namespace App\Services;
|
|
|
|
|
|
2016-04-27 19:13:29 +03:00
|
|
|
use Auth;
|
2016-03-02 15:36:42 +02:00
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
2015-10-28 21:22:07 +02:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* Class BaseService
|
|
|
|
|
*/
|
2015-10-28 21:22:07 +02:00
|
|
|
class BaseService
|
|
|
|
|
{
|
2016-03-02 15:36:42 +02:00
|
|
|
use DispatchesJobs;
|
2015-10-28 21:22:07 +02:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @return null
|
|
|
|
|
*/
|
2015-10-28 21:22:07 +02:00
|
|
|
protected function getRepo()
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @param $ids
|
|
|
|
|
* @param $action
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
2015-10-29 16:42:05 +02:00
|
|
|
public function bulk($ids, $action)
|
2015-10-28 21:22:07 +02:00
|
|
|
{
|
2016-03-15 22:38:42 -04:00
|
|
|
if ( ! $ids ) {
|
2015-10-28 21:22:07 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$entities = $this->getRepo()->findByPublicIdsWithTrashed($ids);
|
|
|
|
|
|
|
|
|
|
foreach ($entities as $entity) {
|
2016-08-02 17:38:51 +03:00
|
|
|
if (Auth::user()->can('edit', $entity)) {
|
2016-03-15 22:07:11 -04:00
|
|
|
$this->getRepo()->$action($entity);
|
|
|
|
|
}
|
2015-10-28 21:22:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count($entities);
|
|
|
|
|
}
|
|
|
|
|
}
|