Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix needed in the default controller Stub #11

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bddf633
updated all the code and added filtering
scheff-code Feb 10, 2021
bf63319
Merge branch 'dev-subviews'
scheff-code Feb 10, 2021
853b81d
Fixed Namespacing
scheff-code Feb 10, 2021
9c3fad4
Merge branch 'dev-subviews'
scheff-code Feb 10, 2021
e2ed8ed
Create test.md
scheff-code Feb 10, 2021
1e561c5
fixed column filters
scheff-code Feb 11, 2021
eedeb69
Merge branch 'dev-subviews'
scheff-code Feb 11, 2021
718f83f
Merge remote-tracking branch 'origin/master'
scheff-code Feb 11, 2021
2bdef8f
Apply fixes from StyleCI
scheff-code Feb 14, 2021
3fc18d4
Merge pull request #1 from scheff-code/analysis-M17p6O
scheff-code Feb 14, 2021
61b2f38
paging and other fixes and tweaks
scheff-code Feb 14, 2021
84ebdee
Merge branch 'fix-paging'
scheff-code Feb 14, 2021
7b205a3
Merge remote-tracking branch 'origin/master'
scheff-code Feb 14, 2021
50a218e
fixed var names
scheff-code Feb 14, 2021
bd2ac37
fixed title
scheff-code Feb 14, 2021
a5929ae
Merge branch 'fix-paging'
scheff-code Feb 14, 2021
47c1d5d
propagated the renaming of the title option
scheff-code Feb 14, 2021
c5adca8
perPage no longer a var
scheff-code Feb 14, 2021
31b2914
fixed publishing path
scheff-code Feb 14, 2021
9f0c388
forgot to update the asset reference
scheff-code Feb 14, 2021
56d5522
added instruction on blade inclusion of js file
scheff-code Feb 14, 2021
583585e
updated version in readme
scheff-code Feb 14, 2021
37b8470
Added Column Sorting, extended Controller
scheff-code Feb 16, 2021
08e95d3
Removed hard-coded column reference
scheff-code Feb 17, 2021
8abce65
fixed th html formatting
scheff-code Feb 17, 2021
92cb2a3
Apply fixes from StyleCI
scheff-code Feb 17, 2021
a49320f
Merge pull request #2 from scheff-code/analysis-Zl0MPa
scheff-code Feb 17, 2021
2c55894
Updated Readme
scheff-code Feb 17, 2021
0c1233a
Merge remote-tracking branch 'origin/master'
scheff-code Feb 17, 2021
e3fd2fa
grammatical fix
scheff-code Feb 17, 2021
471b446
added sort image to readme
scheff-code Feb 17, 2021
05a7880
Adjusted the update signature to use implicit binding
scheff-code Feb 18, 2021
def39ed
added 'page' to the column names to avoid, converted it into an array
scheff-code Mar 2, 2021
e1274f8
added possibility to filter on boolean cols using a yes/no dropdown.
scheff-code Mar 18, 2021
8f0fec4
fixed mismatched div / p tag
scheff-code Apr 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MIT License

Copyright (c) 2020 Daniel Scheff
Copyright (c) 2018 Muhammad Awais

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
![Laravel Crud Generator](https://banners.beyondco.de/Laravel%20CRUD.png?theme=dark&packageManager=composer+require&packageName=ibex%2Fcrud-generator&pattern=architect&style=style_1&description=Laravel+CRUD+Generator&md=1&showWatermark=0&fontSize=100px&images=gift)
![Laravel Crud Generator with Column Filters](https://banners.beyondco.de/Laravel%20Crud%20Generator%20with%20Column%20Filters%20and%20Sorting.png?theme=dark&packageManager=composer+require&packageName=dscheff%2Fcrud-generator&pattern=graphPaper&style=style_1&description=Column+Filtering+and+Sorting+&md=1&showWatermark=0&fontSize=70px&images=filter&images=arrow-narrow-down)


![Packagist](https://img.shields.io/badge/Packagist-v1.1.2-green.svg?style=flat-square)
![Packagist](https://img.shields.io/badge/Packagist-v1.3.10-green.svg?style=flat-square)
![Licence](https://img.shields.io/badge/Licence-MIT-green.svg?style=flat-square)
![StyleCI](https://img.shields.io/badge/StyleCI-pass-green.svg?style=flat-square)

This package is a fork of https://packagist.org/packages/ibex/crud-generator, and adds column sorting and
filtering to the index view, as well as a handful of other tweaks.

This Laravel Generator package generates your MVC code (with eloquent relations) in **Bootstrap** for your app
development, with a single command.

This Laravel Generator package provides and generate Controller, Model (with eloquent relations) and Views in **Bootstrap** for your development of your applications with single command.
@todo - Add related models to the sorting and filtering

@todo - Adding subview generation for views that integrate mutiple models, with
Ajax/modal/inline forms

- Will create **Model** with Eloquent relations
- Will create **Controller** with all resources
- Will create **views** in Bootstrap
- Will create **views** in Bootstrap 4
- Will add **Column Sorting and Filtering** to your index action/view

## Requirements
Laravel >= 5.5
Expand All @@ -19,11 +26,19 @@ This Laravel Generator package provides and generate Controller, Model (with elo
## Installation
1 - Install
```
composer require ibex/crud-generator --dev
composer require dscheff/crud-generator --dev
```
2- Publish the default package's config
2 - Publish the default package's config, and js/css assets
```
php artisan vendor:publish --tag=crud
php artisan vendor:publish --tag=public --force
```

You will need to add the following to your **app layout**, just inside your closing body tag:

```
@stack('scripts-body')
</body>
```

## Usage
Expand All @@ -40,9 +55,16 @@ Route::resource('banks', 'BankController');
Route name in plural slug case.

#### Options
- Custom Route
- Custom Route
```
php artisan make:crud {table_name} --route={route_name}
php artisan make:crud {table_name} --route={route_name}
```

- Custom Display Name for Views
```
php artisan make:crud {table_name} --title={displayed_model_name}

php artisan make:crud sales_rep --title="Sales Representatives"
```

## Example
Expand All @@ -63,10 +85,6 @@ php artisan make:crud {table_name} --route={route_name}
![Form](https://i.imgur.com/poRiZRO.png)


## Author

M Awais // [Email Me](mailto:[email protected])

[Buy me a Coffee](https://ko-fi.com/C0C8VT1M)
## Author(s)

[![ko-fi](https://www.ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/C0C8VT1M)
Daniel Scheff, on the back of the great work of M Awais (https://packagist.org/packages/ibex/crud-generator)
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
{
"name": "ibex/crud-generator",
"description": "Laravel Crud Generator",
"name": "dscheff/crud-generator",
"description": "Laravel Crud Generator with Column Filters",
"license": "MIT",
"authors": [
{
"name": "Daniel Scheff",
"email": "[email protected]"
},
{
"name": "M Awais",
"email": "[email protected]"
}
],
"keywords": ["laravel", "crud", "crud generator", "laravel crud generator", "laravel package"],
"keywords": ["laravel", "column filters", "crud", "crud generator", "laravel crud generator", "laravel package"],
"require": {
"laravel/framework": "^5.5|^6.20.12|^7.0|^8.0",
"laravelcollective/html": "^5.4|^6.0|^7.0|^8.0"
},
"autoload": {
"psr-4": {
"Ibex\\CrudGenerator\\": "src/"
"Dscheff\\CrudGenerator\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Ibex\\CrudGenerator\\CrudServiceProvider"
"Dscheff\\CrudGenerator\\CrudServiceProvider"
]
}
},
Expand Down
73 changes: 47 additions & 26 deletions src/Commands/CrudGenerator.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

namespace Ibex\CrudGenerator\Commands;
namespace Dscheff\CrudGenerator\Commands;

use Illuminate\Support\Str;

/**
* Class CrudGenerator.
*
* @author Daniel Scheff <[email protected]>
* @author Awais <[email protected]>
*/
class CrudGenerator extends GeneratorCommand
Expand All @@ -18,7 +19,10 @@ class CrudGenerator extends GeneratorCommand
*/
protected $signature = 'make:crud
{name : Table name}
{--route= : Custom route name}';
{--route= : Custom route name}
{--title= : Visible model name}';

// {--model-name= : Model name if not studly table name}

/**
* The console command description.
Expand All @@ -27,12 +31,20 @@ class CrudGenerator extends GeneratorCommand
*/
protected $description = 'Create bootstrap CRUD operations';

/**
* The stubs to be generated.
*
* @var array
*/
// protected $stubs = ['index', 'create', 'edit', 'form', 'show', '_index', '_create', '_edit'];
protected $stubs = ['index', 'create', 'edit', 'form', 'show'];

/**
* Execute the console command.
*
* @return bool|null
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*
* @return bool|null
*/
public function handle()
{
Expand Down Expand Up @@ -64,94 +76,103 @@ public function handle()
/**
* Build the Controller Class and save in app/Http/Controllers.
*
* @return $this
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*
* @return $this
*/
protected function buildController()
{
$controllerPath = $this->_getControllerPath($this->name);
$path = $this->_getControllerPath($this->name);

if ($this->files->exists($controllerPath) && $this->ask('Already exist Controller. Do you want overwrite (y/n)?', 'y') == 'n') {
if ($this->files->exists($path) && $this->ask('Controller exists. Overwrite (y/n)?', 'y') == 'n') {
return $this;
}

$this->info('Creating Controller ...');
$this->info('Creating Controller...');

$replace = $this->buildReplacements();

$controllerTemplate = str_replace(
array_keys($replace), array_values($replace), $this->getStub('Controller')
$template = str_replace(
array_keys($replace),
array_values($replace),
$this->getStub('Controller')
);

$this->write($controllerPath, $controllerTemplate);
$this->write($path, $template);

return $this;
}

/**
* @return $this
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*
* @return $this
*/
protected function buildModel()
{
$modelPath = $this->_getModelPath($this->name);
$path = $this->_getModelPath($this->name);

if ($this->files->exists($modelPath) && $this->ask('Already exist Model. Do you want overwrite (y/n)?', 'y') == 'n') {
if ($this->files->exists($path) && $this->ask('Model exists. Overwrite (y/n)?', 'y') == 'n') {
return $this;
}

$this->info('Creating Model ...');
$this->info('Creating Model...');

// Make the models attributes and replacement
$replace = array_merge($this->buildReplacements(), $this->modelReplacements());

$modelTemplate = str_replace(
array_keys($replace), array_values($replace), $this->getStub('Model')
$template = str_replace(
array_keys($replace),
array_values($replace),
$this->getStub('Model')
);

$this->write($modelPath, $modelTemplate);
$this->write($path, $template);

return $this;
}

/**
* @return $this
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*
* @throws \Exception
*
* @return $this
*/
protected function buildViews()
{
$this->info('Creating Views ...');

$tableHead = "\n";
$tableBody = "\n";
$tableColumnFilters = "\n";
$viewRows = "\n";
$form = "\n";

foreach ($this->getFilteredColumns() as $column) {
$title = Str::title(str_replace('_', ' ', $column));

$tableHead .= $this->getHead($title);
$tableHead .= $this->getHead($title, $column);
$tableBody .= $this->getBody($column);
$tableColumnFilters .= $this->getTableColumnFilters($column);
$viewRows .= $this->getField($title, $column, 'view-field');
$form .= $this->getField($title, $column, 'form-field');
}

$replace = array_merge($this->buildReplacements(), [
'{{tableHeader}}' => $tableHead,
'{{tableBody}}' => $tableBody,
'{{viewRows}}' => $viewRows,
'{{form}}' => $form,
'{{tableHeader}}' => $tableHead,
'{{tableBody}}' => $tableBody,
'{{tableColumnFilters}}' => $tableColumnFilters,
'{{viewRows}}' => $viewRows,
'{{form}}' => $form,
]);

$this->buildLayout();

foreach (['index', 'create', 'edit', 'form', 'show'] as $view) {
foreach ($this->stubs as $view) {
$viewTemplate = str_replace(
array_keys($replace), array_values($replace), $this->getStub("views/{$view}")
array_keys($replace),
array_values($replace),
$this->getStub("views/{$view}")
);

$this->write($this->_getViewPath($view), $viewTemplate);
Expand Down
Loading