invoiceninja/app/Console/Commands/stubs/repository.stub

72 lines
1.7 KiB
Text
Raw Normal View History

2016-12-08 17:09:45 +02:00
<?php
2016-12-08 20:00:13 +02:00
namespace $NAMESPACE$;
2016-12-08 17:09:45 +02:00
use DB;
2016-12-08 21:37:07 +02:00
use Modules\$STUDLY_NAME$\Models\$STUDLY_NAME$;
2016-12-08 20:00:13 +02:00
use App\Ninja\Repositories\BaseRepository;
2016-12-08 17:09:45 +02:00
//use App\Events\$STUDLY_NAME$WasCreated;
//use App\Events\$STUDLY_NAME$WasUpdated;
class $STUDLY_NAME$Repository extends BaseRepository
{
public function getClassName()
{
2016-12-09 00:34:24 +02:00
return 'Modules\$STUDLY_NAME$\Models\$STUDLY_NAME$';
2016-12-08 17:09:45 +02:00
}
2016-12-09 10:43:20 +02:00
public function all()
{
return $STUDLY_NAME$::scope()
->orderBy('created_at', 'desc')
->withTrashed();
}
2016-12-08 17:09:45 +02: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-09 00:18:10 +02:00
$DATABASE_FIELDS$
2016-12-08 17:09:45 +02:00
'$LOWER_NAME$.public_id',
'$LOWER_NAME$.deleted_at',
2016-12-08 22:39:15 +02:00
'$LOWER_NAME$.created_at',
2016-12-08 17:09:45 +02: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 11:51:18 +02:00
/*
if ($filter) {
$query->where();
}
2016-12-08 17:09:45 +02:00
*/
2016-12-08 20:00:13 +02:00
2016-12-08 17:09:45 +02:00
return $query;
}
2016-12-08 21:37:07 +02:00
public function save($data, $$LOWER_NAME$ = null)
2016-12-08 17:09:45 +02:00
{
2016-12-08 21:37:07 +02:00
$entity = $$LOWER_NAME$ ?: $STUDLY_NAME$::createNew();
2016-12-08 17:09:45 +02:00
2016-12-09 00:06:31 +02:00
$entity->fill($data);
2016-12-08 21:37:07 +02:00
$entity->save();
2016-12-08 17:09:45 +02:00
/*
2018-06-19 22:46:35 +03:00
if (!$publicId || intval($publicId) < 0) {
2016-12-08 17:09:45 +02:00
event(new ClientWasCreated($client));
} else {
event(new ClientWasUpdated($client));
}
*/
2016-12-08 21:37:07 +02:00
return $entity;
2016-12-08 17:09:45 +02:00
}
}