Skip to content

Commit

Permalink
Create v2.2.3 along with more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Oct 22, 2017
1 parent a78b079 commit 2dc0577
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 82 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Upgrade
- If you are upgrading from v2.0 or v2.1 to v2.3 make sure you publish the vendor resource. There are some changes to the templates that required to be updated.
- If you are upgrading from v2.0, v2.1 or v2.2 to v2.3 make sure you publish the vendor resource. There are some updates to the config file.
- If you are upgrading from v2.0 or v2.1 to v2.2 make sure you publish the vendor resource. There are some changes to the templates that required to be updated.
-- If you are upgrading any version prior v2.2 follow the upgrate instruction on https://crestapps.com/laravel-code-generator/docs/2.2#upgrade-guide

### Options Changes
Expand Down
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# An awesome code generator for laravel framework - with client-side validation

For full documentation and live demo please visit <a href="https://crestapps.com/laravel-code-generator/docs/2.2" target="_blank" title="Laravel Code Generator Documentation">CrestApps.com</a>

## Introduction

A clean code generator for Laravel framework that will save you time! This awesome tool will help you generate resources like views, controllers, routes, migrations, languages or request-forms! It is extremely flexible and customizable to cover many on the use cases. It is shipped with cross-browsers compatible template, along with a client-side validation to modernize your application.
An intelligent code generator for Laravel framework that will save you time! This awesome tool will help you generate resources like views, controllers, routes, migrations, languages and/or form-requests! It is extremely flexible and customizable to cover many on the use cases. It is shipped with cross-browsers compatible template, along with a client-side validation to modernize your application.

For full documentation and live demo please visit <a href="https://crestapps.com/laravel-code-generator/docs/2.2" target="_blank" title="Laravel Code Generator Documentation">CrestApps.com</a>

## Features

Expand Down Expand Up @@ -40,31 +38,32 @@ A clean code generator for Laravel framework that will save you time! This aweso

1. To download this package into your laravel project, use the command-line to execute the following command

```
composer require crestapps/laravel-code-generator --dev
```
```
composer require crestapps/laravel-code-generator --dev
```

2. **(You may skip this step when using Laravel >= 5.5)** To bootstrap the packages into your project while using command-line only, open the app/Providers/AppServiceProvider.php file in your project. Then, add the following code to the register() method.

Add the following line to bootstrap laravel-code-generator to the framework.
Add the following line to bootstrap laravel-code-generator to the framework.

```
if ($this->app->runningInConsole()) {
$this->app->register('CrestApps\CodeGenerator\CodeGeneratorServiceProvider');
}
```
```
if ($this->app->runningInConsole()) {
$this->app->register('CrestApps\CodeGenerator\CodeGeneratorServiceProvider');
}
```

3. Execute the following command from the command-line to publish the package's config and the default template to start generating awesome code.
```
php artisan vendor:publish --provider="CrestApps\CodeGenerator\CodeGeneratorServiceProvider" --tag=default
```

```
php artisan vendor:publish --provider="CrestApps\CodeGenerator\CodeGeneratorServiceProvider" --tag=default
```

> A layout is required for the default views! The code generator allows you to create a layout using the command-line. Of cource you can use your own layout. You'll only need to include [CSS bootstrap framework](http://getbootstrap.com/ "CSS bootstrap framework") in your layout for the default templates to work properly. Additionally, you can chose to you design your own templetes using a different or no css framework.
## Lessons
Checkout our YouTube channel
> https://youtu.be/l21qNcsMAWg
> https://youtu.be/infoecfXOCw
Checkout our YouTube channel on <a href="https://www.youtube.com/channel/UCkEd0nOoRf3o0ahspAu7Y9w/videos" target="_blank" title="CrestApps YouTube Channel">YouTube.com</a>
* https://youtu.be/l21qNcsMAWg
* https://youtu.be/infoecfXOCw


## Available Commands
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "crestapps/laravel-code-generator",
"license": "MIT",
"description": "A clean code generator for Laravel framework that will save you time! This awesome tool will help you generate resources like views, controllers, routes, migrations, languages or request-forms! It is extremely flexible and customizable to cover many use cases. It is shipped with cross-browsers compatible template, along with a client-side validation to modernize your application.",
"version": "v2.2.2",
"version": "v2.2.3",
"keywords": [
"laravel","crud","crud generator",
"laravel crud generator","laravel crud builder",
Expand Down
9 changes: 6 additions & 3 deletions config/codegenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,17 @@
| Key phrases that are will be used to determine if a field name should be
| used for header.
|--------------------------------------------------------------------------
|
| You may use * as a while card in the name. For example, "head*" will
| match any field name that starts with the word "head"
|
*/
'common_header_patterns' => [
'title',
'name',
'label',
'header',
'subject',
'head',
'head*',
],

/*
Expand Down Expand Up @@ -284,6 +286,7 @@
[
'match' => '*',
'set' => [
// You may use any of the field templates to create the label
'labels' => '[% field_name_title %]',
],
],
Expand All @@ -302,7 +305,7 @@
],
],
[
'match' => ['title', 'name', 'label', 'header'],
'match' => ['title', 'name', 'label', 'subject', 'head*'],
'set' => [
'is-nullable' => false,
'data-type' => 'string',
Expand Down
26 changes: 3 additions & 23 deletions src/Models/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ class Field implements JsonWriter
*/
private $labels = [];

/**
* The languages for the labels
*
* @var array
*/
private $languages = [];

/**
* The html-type of the field
*
Expand Down Expand Up @@ -369,15 +362,13 @@ class Field implements JsonWriter
*
* @param string $name
* @param string $localeGroup
* @param array $languages
*
* @return void
*/
public function __construct($name, $localeGroup, $languages)
public function __construct($name, $localeGroup)
{
$this->name = $name;
$this->localeGroup = $localeGroup;
$this->languages = $languages;
$this->defaultLang = App::getLocale();
}

Expand Down Expand Up @@ -1133,16 +1124,6 @@ protected function getLabelsFromProperties(array $properties)
];
}

/**
* Checks if the field has languages
*
* @return bool
*/
protected function isMultiLingual()
{
return !empty($this->langauges);
}

/**
* It set the validationRules property for a giving field
*
Expand Down Expand Up @@ -1785,19 +1766,18 @@ public static function getNameFromArray(array $properties)
*
* @param array $properties
* @param string $localeGroup
* @param array $languages
*
* @return $this
*/
public static function fromArray(array $properties, $localeGroup, $languages = [])
public static function fromArray(array $properties, $localeGroup)
{
$fieldName = self::getNameFromArray($properties);

if (!Field::isValidHtmlType($properties)) {
unset($properties['html-type']);
}

$field = new self($fieldName, $localeGroup, $languages);
$field = new self($fieldName, $localeGroup);

$field->setPredefindProperties($properties)
->setLabelsProperty($properties)
Expand Down
29 changes: 17 additions & 12 deletions src/Models/ForeignRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,24 @@ public function getName()
*/
protected function guessForeignField()
{
// First we try to find a column that match the header pattern
$columns = $this->getModelColumns();
$names = Config::getHeadersPatterns();

foreach ($columns as $column) {
$matchedPattern = '';
if (Helpers::strIs($names, $column, $matchedPattern)) {
if (Helpers::strIs($names, $column)) {
// At this point a column that match the header patter was found
return $column;
}
}

// At this point we know no column that match the header patters found.
// Second we try to find a non-primary/non-foreign key column
$primary = $this->getPrimaryKeyForForeignModel();
$idPatterns = Config::getKeyPatterns();
$columns = array_filter($columns, function ($column) use ($primary, $idPatterns) {

return $column != $primary && !Helpers::strIs($idPatterns, $column);
});

if (count($columns) > 0) {
return current($columns);
foreach ($columns as $column) {
if ($column != $primary && !Helpers::strIs($idPatterns, $column)) {
return $column;
}
}

return $primary;
Expand Down Expand Up @@ -293,11 +292,17 @@ public function getModelColumns()
$model = $this->getForeignModelInstance();
$columns = [];
if ($this->isModel($model)) {
// At this point we know a model class exists
// Try to get the database column listing from the database directly
$tableName = $model->getTable();
$columns = DB::getSchemaBuilder()->getColumnListing($tableName);
}

if (count($columns) == 0) {
// At this poing we know the column have not yet been identified
// which also mean that the model does not exists or the table
// does not existing in the database.
// Try to find the columns from the resource-file if one found.
$columns = $this->getFieldNamesFromResource();
}

Expand Down Expand Up @@ -344,10 +349,10 @@ protected function getFieldNamesFromResource()
protected function getForeignResource()
{
$modelName = $this->getForeignModelName();
// Find the resource file from the resource-map or make a standard name.
$resourceFile = ResourceMapper::pluckFirst($modelName) ?: Helpers::makeJsonFileName($modelName);
$resourceFileFullName = Config::getResourceFilePath($resourceFile);

if (File::exists($resourceFileFullName)) {
if (File::exists(Config::getResourceFilePath($resourceFile))) {
return Resource::fromFile($resourceFile, 'crestapps');
}

Expand Down
4 changes: 0 additions & 4 deletions src/Support/FieldTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,6 @@ protected function getOptions(array $options)

// At this point we are just formatting the labels
foreach ($options as $key => $option) {
if (is_array($option)) {
dd($option, $this->hasLanguages(), $this->languages);
}

$labels[$key] = Helpers::convertNameToLabel($option);
}
}
Expand Down
42 changes: 24 additions & 18 deletions src/Support/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Helpers
*/
public static function makeControllerName($modelName)
{
$case = ucfirst(camel_case(self::getProperCaseFor($modelName, 'controller-name')));
$name = self::getProperCaseFor($modelName, 'controller-name');
$case = ucfirst(camel_case($name));

if (!empty($postFix = Config::getControllerNamePostFix())) {
return str_finish($case, $postFix);
Expand Down Expand Up @@ -81,7 +82,8 @@ public static function convertNameToLabel($name)
*/
public static function makeFormRequestName($modelName)
{
$case = ucfirst(camel_case(self::getProperCaseFor($modelName, 'request-form-name')));
$name = self::getProperCaseFor($modelName, 'request-form-name');
$case = ucfirst(camel_case($name));

if (!empty($postFix = Config::getFormRequestNamePostFix())) {
return str_finish($case, $postFix);
Expand Down Expand Up @@ -150,7 +152,9 @@ public static function guessModelFullName($name, $modelsPath)
*/
public static function extractModelName($name)
{
return ucfirst(studly_case(Str::singular(str_replace('_id', '', $name))));
$name = self::removePostFixWith($name, '_id');

return ucfirst(studly_case(Str::singular($name)));
}

/**
Expand Down Expand Up @@ -266,9 +270,9 @@ public static function isNewerThanOrEqualTo($version = '5.3')
*/
public static function strReplaceOnce($pattern, $replacment, $subject)
{
if (strpos($subject, $pattern) !== false) {
$occurrence = strpos($subject, $pattern);
return substr_replace($subject, $replacment, strpos($subject, $pattern), strlen($pattern));
$index = strpos($subject, $pattern);
if ($index !== false) {
return substr_replace($subject, $replacment, $index, strlen($pattern));
}

return $subject;
Expand Down Expand Up @@ -392,14 +396,16 @@ public static function stringToBool($str)
* Removes a string from the end of another giving string if it already ends with it.
*
* @param string $name
* @param string $postFix
* @param string $fix
*
* @return string
*/
public static function removePostFixWith($name, $postFix = '/')
public static function removePostFixWith($name, $fix = '/')
{
if (ends_with($name, $postFix)) {
return strstr($name, $postFix, true);
$position = strripos($name, $fix);

if ($position !== false) {
return substr($name, 0, $position);
}

return $name;
Expand All @@ -409,14 +415,14 @@ public static function removePostFixWith($name, $postFix = '/')
* Adds a postFix string at the end of another giving string if it does not already ends with it.
*
* @param string $name
* @param string $postFix
* @param string $fix
*
* @return string
*/
public static function postFixWith($name, $postFix = '/')
public static function postFixWith($name, $fix = '/')
{
if (!ends_with($name, $postFix)) {
return $name . $postFix;
if (!ends_with($name, $fix)) {
return $name . $fix;
}

return $name;
Expand All @@ -426,14 +432,14 @@ public static function postFixWith($name, $postFix = '/')
* Adds a preFix string at the begining of another giving string if it does not already ends with it.
*
* @param string $name
* @param string $preFix
* @param string $fix
*
* @return string
*/
public static function preFixWith($name, $preFix = '/')
public static function preFixWith($name, $fix = '/')
{
if (!starts_with($name, $preFix)) {
return $preFix . $name;
if (!starts_with($name, $fix)) {
return $fix . $name;
}

return $name;
Expand Down

0 comments on commit 2dc0577

Please sign in to comment.