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

76 lines
2 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
}
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 ($filter) {
$query->where(function ($query) use ($filter) {
$query->where('clients.name', 'like', '%'.$filter.'%')
->orWhere('contacts.first_name', 'like', '%'.$filter.'%')
->orWhere('contacts.last_name', 'like', '%'.$filter.'%')
->orWhere('contacts.email', 'like', '%'.$filter.'%');
});
}
if ($userId) {
$query->where('clients.user_id', '=', $userId);
}
*/
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-08 21:37:07 +02:00
/*
if ($entity->is_deleted) {
return $entity;
2016-12-08 17:09:45 +02:00
}
2016-12-08 21:37:07 +02:00
*/
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
/*
if (!$publicId || $publicId == '-1') {
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
}
}