Skip to content

Commit

Permalink
Fix - Controller resource name was formatted incorrectly - Thanks @ma…
Browse files Browse the repository at this point in the history
  • Loading branch information
bpocallaghan committed May 2, 2017
1 parent 17e845c commit c54131a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 43 deletions.
71 changes: 37 additions & 34 deletions resources/stubs/view.add_edit.stub
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,43 @@

@include('admin.partials.info')

{!! Form::open(['method' => isset($item)? 'put':'post', 'url' => $selectedNavigation->url . (isset($item)? $item->id : '')]) !!}

<fieldset>
<div class="row">
<section class="col col-6">
<section class="form-group {{ form_error_class('title', $errors) }}">
<label for="id-title">Title</label>
<input type="text" class="form-control input-generate-slug" id="id-title" name="title" placeholder="Please insert the Title" value="{{ ($errors && $errors->any()? old('title') : (isset($item)? $item->title : '')) }}">
{!! form_error_message('title', $errors) !!}
</section>
</section>

<section class="col col-6">
<section class="form-group {{ form_error_class('slug', $errors) }}">
<label for="id-slug">Slug</label>
<div class="input-group">
<input type="text" class="form-control" id="id-slug" name="slug" placeholder="Please insert the Slug" value="{{ ($errors && $errors->any()? old('slug') : (isset($item)? $item->slug : '')) }}">
<span class="input-group-addon"><i class="fa fa-link"></i></span>
</div>
{!! form_error_message('slug', $errors) !!}
</section>
</section>
</div>

<section class="form-group {{ form_error_class('description', $errors) }}">
<label for="id-description">Description</label>
<input type="text" class="form-control" id="id-description" name="description" placeholder="Please insert the Description" value="{{ ($errors && $errors->any()? old('description') : (isset($item)? $item->description : '')) }}">
{!! form_error_message('description', $errors) !!}
</section>
</fieldset>

@include('admin.partials.form_footer')

{!! Form::close() !!}
<form method="POST" action="{{$selectedNavigation->url . (isset($item)? $item->id : '')}}" accept-charset="UTF-8">

<input name="_token" type="hidden" value="{{ csrf_token() }}">
<input name="_method" type="hidden" value="{{isset($item)? 'PUT':'POST'}}">

<fieldset>
<div class="row">
<section class="col col-6">
<section class="form-group {{ form_error_class('title', $errors) }}">
<label for="id-title">Title</label>
<input type="text" class="form-control input-generate-slug" id="id-title" name="title" placeholder="Please insert the Title" value="{{ ($errors && $errors->any()? old('title') : (isset($item)? $item->title : '')) }}">
{!! form_error_message('title', $errors) !!}
</section>
</section>

<section class="col col-6">
<section class="form-group {{ form_error_class('slug', $errors) }}">
<label for="id-slug">Slug</label>
<div class="input-group">
<input type="text" class="form-control" id="id-slug" name="slug" placeholder="Please insert the Slug" value="{{ ($errors && $errors->any()? old('slug') : (isset($item)? $item->slug : '')) }}">
<span class="input-group-addon"><i class="fa fa-link"></i></span>
</div>
{!! form_error_message('slug', $errors) !!}
</section>
</section>
</div>

<section class="form-group {{ form_error_class('description', $errors) }}">
<label for="id-description">Description</label>
<input type="text" class="form-control" id="id-description" name="description" placeholder="Please insert the Description" value="{{ ($errors && $errors->any()? old('description') : (isset($item)? $item->description : '')) }}">
{!! form_error_message('description', $errors) !!}
</section>
</fieldset>

@include('admin.partials.form_footer')

</form>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/FileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected function buildClass($name)
$stub = str_replace('{{collection}}', $this->getCollectionName(), $stub);

// Bars
$stub = str_replace('{{collectionUpper}}', ucwords($this->getCollectionName()), $stub);
$stub = str_replace('{{collectionUpper}}', $this->getCollectionUpperName(), $stub);

// Bar
$stub = str_replace('{{model}}', $this->getModelName(), $stub);
Expand Down
18 changes: 18 additions & 0 deletions src/Commands/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,24 @@ protected function getCollectionName($name = null)
return str_plural($this->getResourceName($name));
}

/**
* Get the plural uppercase name of the resouce
* @param null $name
* @return null|string
*/
protected function getCollectionUpperName($name = null)
{
$name = str_plural($this->getResourceName($name));

$pieces = explode('_', $name);
$name = "";
foreach ($pieces as $k => $str) {
$name .= ucfirst($str);
}

return $name;
}

/**
* Get the path to the view file
*
Expand Down
9 changes: 1 addition & 8 deletions src/Commands/ResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function fire()
$this->callMigrate();

$this->info('All Done!');
$this->info('Remember to add ' . "`Route::resource('" . $this->getCollectionName() . "', '" . $this->getResourceControllerName() . "');`" . ' in `routes\\web.php`');
$this->info('Remember to add ' . "`Route::resource('" . str_replace('_', '-', $this->getCollectionName()) . "', '" . $this->getResourceControllerName() . "');`" . ' in `routes\\web.php`');
}

/**
Expand Down Expand Up @@ -90,13 +90,6 @@ private function callController()
$arg = $this->getArgumentResource();
$name = substr_replace($arg, str_plural($this->resource), strrpos($arg, $this->resource), strlen($this->resource));

// foo.bar_baz == foo.barBaz
$pieces = explode('_', $name);
$name = "";
foreach ($pieces as $k => $str) {
$name .= ucfirst($str);
}

$this->callCommandFile('controller', $name);
}
}
Expand Down

0 comments on commit c54131a

Please sign in to comment.