1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Working on CRUD

This commit is contained in:
Hillel Coren 2016-12-08 21:37:07 +02:00
parent 6dc6658db1
commit ce724fe1c9
8 changed files with 76 additions and 35 deletions

View File

@ -53,7 +53,14 @@ class $CLASS$ extends BaseController
*/
public function create()
{
return view('$LOWER_NAME$::create');
$data = [
'$LOWER_NAME$' => null,
'method' => 'POST',
'url' => '$LOWER_NAME$',
'title' => trans('texts.new_$LOWER_NAME$'),
];
return view('$LOWER_NAME$::edit', $data);
}
/**
@ -63,6 +70,11 @@ class $CLASS$ extends BaseController
*/
public function store(Request $request)
{
$client = $this->$LOWER_NAME$Repo->save($request->input());
Session::flash('message', trans('texts.created_$LOWER_NAME$'));
return redirect()->to($$LOWER_NAME$->getRoute());
}
/**

View File

@ -17,4 +17,6 @@ class $CLASS$ extends EntityModel
protected $presenter = 'App\Ninja\Presenters\$CLASS$Presenter';
protected $fillable = $FILLABLE$;
protected $table = '$LOWER_NAME$';
}

View File

@ -3,7 +3,7 @@
namespace $NAMESPACE$;
use DB;
use App\Models\$STUDLY_NAME$;
use Modules\$STUDLY_NAME$\Models\$STUDLY_NAME$;
use App\Ninja\Repositories\BaseRepository;
//use App\Events\$STUDLY_NAME$WasCreated;
//use App\Events\$STUDLY_NAME$WasUpdated;
@ -46,24 +46,18 @@ class $STUDLY_NAME$Repository extends BaseRepository
return $query;
}
public function save($data, $client = null)
public function save($data, $$LOWER_NAME$ = null)
{
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
$entity = $$LOWER_NAME$ ?: $STUDLY_NAME$::createNew();
if ($client) {
// do nothing
} elseif (!$publicId || $publicId == '-1') {
$client = Client::createNew();
} else {
$client = Client::scope($publicId)->with('contacts')->firstOrFail();
/*
if ($entity->is_deleted) {
return $entity;
}
*/
if ($client->is_deleted) {
return $client;
}
$client->fill($data);
$client->save();
$entity->fill($data);
$entity->save();
/*
if (!$publicId || $publicId == '-1') {
@ -73,7 +67,7 @@ class $STUDLY_NAME$Repository extends BaseRepository
}
*/
return $client;
return $entity;
}
}

View File

@ -1,11 +1,7 @@
<?php
Route::group(['middleware' => 'auth', 'prefix' => '$LOWER_NAME$', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function()
{
Route::get('/', '$STUDLY_NAME$Controller@index');
});
Route::group(['middleware' => 'auth', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function()
{
Route::resource('$LOWER_NAME$', '$STUDLY_NAME$Controller');
Route::get('api/$LOWER_NAME$', '$STUDLY_NAME$Controller@getDatatable');
});

View File

@ -0,0 +1,47 @@
@extends('header')
@section('content')
{!! Former::open($url)
->addClass('col-md-10 col-md-offset-1 warn-on-exit')
->method($method)
->rules([]) !!}
@if ($$LOWER_NAME$)
{!! Former::populate($$LOWER_NAME$) !!}
<div style="display:none">
{!! Former::text('public_id') !!}
</div>
@endif
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-body">
</div>
</div>
</div>
</div>
<center class="buttons">
{!! Button::normal(trans('texts.cancel'))
->large()
->asLinkTo(URL::to('/$LOWER_NAME$'))
->appendIcon(Icon::create('remove-circle')) !!}
{!! Button::success(trans('texts.save'))
->submit()
->large()
->appendIcon(Icon::create('floppy-disk')) !!}
</center>
{!! Former::close() !!}
@stop

View File

@ -1,9 +0,0 @@
@extends('header')
@section('content')
<h1>Hello World</h1>
<p>
This view is loaded from module: {!! config('$LOWER_NAME$.name') !!}
</p>
@stop

View File

@ -65,14 +65,13 @@ class EntityModel extends Eloquent
// store references to the original user/account to prevent needing to reload them
$entity->setRelation('user', $user);
$entity->setRelation('account', $account);
if (method_exists($className, 'trashed')){
$lastEntity = $className::whereAccountId($entity->account_id)->withTrashed();
} else {
$lastEntity = $className::whereAccountId($entity->account_id);
}
if (static::$hasPublicId) {
$lastEntity = $lastEntity->orderBy('public_id', 'DESC')
->first();

View File

@ -29,7 +29,7 @@ return [
'start' => 'start.php',
'routes' => 'Http/routes.php',
'json' => 'module.json',
'views/index' => 'Resources/views/index.blade.php',
'views/edit' => 'Resources/views/edit.blade.php',
'views/master' => 'Resources/views/layouts/master.blade.php',
'scaffold/config' => 'Config/config.php',
'composer' => 'composer.json',
@ -38,7 +38,7 @@ return [
'start' => ['LOWER_NAME'],
'routes' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE'],
'views/index' => ['LOWER_NAME'],
'views/edit' => ['LOWER_NAME'],
'views/master' => ['STUDLY_NAME'],
'scaffold/config' => ['STUDLY_NAME'],
'composer' => [