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() 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) 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 $presenter = 'App\Ninja\Presenters\$CLASS$Presenter';
protected $fillable = $FILLABLE$; protected $fillable = $FILLABLE$;
protected $table = '$LOWER_NAME$';
} }

View File

@ -3,7 +3,7 @@
namespace $NAMESPACE$; namespace $NAMESPACE$;
use DB; use DB;
use App\Models\$STUDLY_NAME$; use Modules\$STUDLY_NAME$\Models\$STUDLY_NAME$;
use App\Ninja\Repositories\BaseRepository; use App\Ninja\Repositories\BaseRepository;
//use App\Events\$STUDLY_NAME$WasCreated; //use App\Events\$STUDLY_NAME$WasCreated;
//use App\Events\$STUDLY_NAME$WasUpdated; //use App\Events\$STUDLY_NAME$WasUpdated;
@ -46,24 +46,18 @@ class $STUDLY_NAME$Repository extends BaseRepository
return $query; 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 if ($entity->is_deleted) {
} elseif (!$publicId || $publicId == '-1') { return $entity;
$client = Client::createNew();
} else {
$client = Client::scope($publicId)->with('contacts')->firstOrFail();
} }
*/
if ($client->is_deleted) { $entity->fill($data);
return $client; $entity->save();
}
$client->fill($data);
$client->save();
/* /*
if (!$publicId || $publicId == '-1') { 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 <?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::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'); 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

@ -72,7 +72,6 @@ class EntityModel extends Eloquent
$lastEntity = $className::whereAccountId($entity->account_id); $lastEntity = $className::whereAccountId($entity->account_id);
} }
if (static::$hasPublicId) { if (static::$hasPublicId) {
$lastEntity = $lastEntity->orderBy('public_id', 'DESC') $lastEntity = $lastEntity->orderBy('public_id', 'DESC')
->first(); ->first();

View File

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