2016-12-08 16:09:45 +01:00
|
|
|
<?php
|
|
|
|
|
2016-12-08 19:00:13 +01:00
|
|
|
namespace $NAMESPACE$;
|
2016-12-08 16:09:45 +01:00
|
|
|
|
|
|
|
use DB;
|
2016-12-08 20:37:07 +01:00
|
|
|
use Modules\$STUDLY_NAME$\Models\$STUDLY_NAME$;
|
2016-12-08 19:00:13 +01:00
|
|
|
use App\Ninja\Repositories\BaseRepository;
|
2016-12-08 16:09:45 +01:00
|
|
|
//use App\Events\$STUDLY_NAME$WasCreated;
|
|
|
|
//use App\Events\$STUDLY_NAME$WasUpdated;
|
|
|
|
|
|
|
|
class $STUDLY_NAME$Repository extends BaseRepository
|
|
|
|
{
|
|
|
|
public function getClassName()
|
|
|
|
{
|
2016-12-08 23:34:24 +01:00
|
|
|
return 'Modules\$STUDLY_NAME$\Models\$STUDLY_NAME$';
|
2016-12-08 16:09:45 +01:00
|
|
|
}
|
|
|
|
|
2016-12-09 09:43:20 +01:00
|
|
|
public function all()
|
|
|
|
{
|
|
|
|
return $STUDLY_NAME$::scope()
|
|
|
|
->orderBy('created_at', 'desc')
|
|
|
|
->withTrashed();
|
|
|
|
}
|
|
|
|
|
2016-12-08 16:09:45 +01:00
|
|
|
public function find($filter = null, $userId = false)
|
|
|
|
{
|
|
|
|
$query = DB::table('$LOWER_NAME$')
|
|
|
|
->where('$LOWER_NAME$.account_id', '=', \Auth::user()->account_id)
|
|
|
|
->select(
|
2016-12-08 23:18:10 +01:00
|
|
|
$DATABASE_FIELDS$
|
2016-12-08 16:09:45 +01:00
|
|
|
'$LOWER_NAME$.public_id',
|
|
|
|
'$LOWER_NAME$.deleted_at',
|
2016-12-08 21:39:15 +01:00
|
|
|
'$LOWER_NAME$.created_at',
|
2016-12-08 16:09:45 +01:00
|
|
|
'$LOWER_NAME$.is_deleted',
|
|
|
|
'$LOWER_NAME$.user_id'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->applyFilters($query, '$LOWER_NAME$');
|
|
|
|
|
|
|
|
if ($userId) {
|
|
|
|
$query->where('clients.user_id', '=', $userId);
|
|
|
|
}
|
2016-12-09 10:51:18 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
if ($filter) {
|
|
|
|
$query->where();
|
|
|
|
}
|
2016-12-08 16:09:45 +01:00
|
|
|
*/
|
2016-12-08 19:00:13 +01:00
|
|
|
|
2016-12-08 16:09:45 +01:00
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
2016-12-08 20:37:07 +01:00
|
|
|
public function save($data, $$LOWER_NAME$ = null)
|
2016-12-08 16:09:45 +01:00
|
|
|
{
|
2016-12-08 20:37:07 +01:00
|
|
|
$entity = $$LOWER_NAME$ ?: $STUDLY_NAME$::createNew();
|
2016-12-08 16:09:45 +01:00
|
|
|
|
2016-12-08 23:06:31 +01:00
|
|
|
$entity->fill($data);
|
2016-12-08 20:37:07 +01:00
|
|
|
$entity->save();
|
2016-12-08 16:09:45 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
if (!$publicId || $publicId == '-1') {
|
|
|
|
event(new ClientWasCreated($client));
|
|
|
|
} else {
|
|
|
|
event(new ClientWasUpdated($client));
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2016-12-08 20:37:07 +01:00
|
|
|
return $entity;
|
2016-12-08 16:09:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|