2017 © Pedro Peláez
 

library rapyd

crud widgets for laravel 4, to make an admin in few lines of code

image

emiliosh/rapyd

crud widgets for laravel 4, to make an admin in few lines of code

  • Wednesday, February 14, 2018
  • by emiliosh
  • Repository
  • 1 Watchers
  • 0 Stars
  • 153 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 12 % Grown

The README.md

rapyd-laravel

, (*1)

This is a pool of presentation and editing widgets (Grids and Forms) for laravel 4.
Nothing to "generate", just some classes to let you develop and maintain CRUD backends in few lines of code., (*2)

Main Website: rapyd.com
Demo: rapyd.com/demo
Documentation: Wiki, (*3)

rapyd laravel, (*4)

DataGrid

DataGrid extend DataSet to make data-grid output with few lines of fluent code.
It build a bootstrap striped table, with pagination at bottom and order-by links on table header. It support also blade syntax, filters, closures etc.., (*5)

in a controller, (*6)

   $grid = DataGrid::source(Article::with('author'));  //same source types of DataSet

   $grid->add('title','Title', true); //field name, label, sortable
   $grid->add('author.fullname','author'); //relation.fieldname 
   $grid->add('{{ substr($body,0,20) }}...','Body'); //blade syntax with main field
   $grid->add('{{ $author->firstname }}','Author'); //blade syntax with related field
   $grid->add('body|strip_tags|substr[0,20]','Body'); //filter (similar to twig syntax)
   $grid->add('body','Body')->filter('strip_tags|substr[0,20]'); //another way to filter
   $grid->edit('/articles/edit', 'Edit','modify|delete'); //shortcut to link DataEdit actions
   $grid->link('/articles/edit',"Add New", "TR");  //add button
   $grid->orderBy('article_id','desc'); //default orderby
   $grid->paginate(10); //pagination

   View::make('articles', compact('grid'))

in a view you can just write, (*7)

  #articles.blade.php
  {{ $grid }}

styling a datagrid, (*8)

   ...
   $grid->add('title','Title', true)->style("width:100px"); //adding style to th
   $grid->add('body','Body')->attr("class","custom_column"); //adding class to a th
   ...
    //row and cell manipulation via closure
    $grid->row(function ($row) {
       if ($row->cell('public')->value < 1) {
           $row->cell('title')->style("color:Gray");
           $row->style("background-color:#CCFF66");
       }  
    });
    ...

datagrid supports also csv output, so it can be used as "report" tool., (*9)

   ...
   $grid->add('title','Title');
   $grid->add('body','Body')
   ...
   $grid->buildCSV();  //  force download 
   $grid->buildCSV('export_articles', 'Y-m-d.His');  // force download with custom stamp
   $grid->buildCSV('uploads/filename', 'Y-m-d');  // write on file 
    ...

DataForm

DataForm is a form builder, you can add fields, rules and buttons.
It will build a bootstrap form, on submit it will check rules and if validation pass it'll store new entity., (*10)

   //start with empty form to create new Article
   $form = DataForm::source(new Article);

   //or find a record to update some value
   $form = DataForm::source(Article::find(1));

   //add fields to the form
   $form->add('title','Title', 'text'); //field name, label, type
   $form->add('body','Body', 'textarea')->rule('required'); //validation

   //some enhanced field (images, wysiwyg, autocomplete, etc..):
   $form->add('photo','Photo', 'image')->move('uploads/images/')->preview(80,80);
   $form->add('body','Body', 'redactor'); //wysiwyg editor
   $form->add('author.name','Author','autocomplete')->search(array('firstname','lastname'));
   $form->add('categories.name','Categories','tags'); //tags field

   //you can also use now the smart syntax for all fields: 
   $form->text('title','Title'); //field name, label
   $form->textarea('body','Body')->rule('required'); //validation
   ...

   $form->submit('Save');
   $form->saved(function() use ($form)
   {
        $form->message("ok record saved");
        $form->link("/another/url","Next Step");
   });

   View::make('article', compact('form'))
   #article.blade.php
  {{ $form }}

DataForm explained, (*11)

customize form in view

You can directly customize form using build() in your controller, (*12)

php ... $form->build(); View::make('article', compact('form')) then in the view you can use something like this:, (*13)

   #article.blade.php
    {{ $form->header }}

        {{ $form->message }} <br />

        @if(!$form->message)

            Title:  {{ $form->field('title') }}<br /> 
            Body:  {{ $form->field('body') }}
            ...

        @endif

    {{ $form->footer }}

custom form layout explained
custom form layout demo, (*14)

DataEdit

DataEdit extends DataForm, it's a full CRUD application for given Entity.
It has status (create, modify, show) and actions (insert, update, delete) It detect status by simple query string semantic:, (*15)

  /dataedit/uri                     empty form    to CREATE new records
  /dataedit/uri?show={record_id}    filled output to READ record (without form)
  /dataedit/uri?modify={record_id}  filled form   to UPDATE a record
  /dataedit/uri?delete={record_id}  perform   record DELETE
  ...
   //simple crud for Article entity
   $edit = DataEdit::source(new Article);
   $edit->link("article/list","Articles", "TR")->back();
   $edit->add('title','Title', 'text')->rule('required');
   $edit->add('body','Body','textarea')->rule('required');
   $edit->add('author.name','Author','autocomplete')->search(array('firstname','lastname'));

   //you can also use now the smart syntax for all fields: 
   $edit->textarea('title','Title'); 
   $edit->autocomplete('author.name','Author')->search(array('firstname','lastname'));

   return $edit->view('crud', compact('edit'));

   #crud.blade.php
  {{ $edit }}

DataEdit explained, (*16)

DataFilter

DataFilter extends DataForm, each field you add and each value you fill in that form is used to build a __where clause__ (by default using 'like' operator).
It should be used in conjunction with a DataSet or DataGrid to filter results., (*17)

   $filter = DataFilter::source(new Article);
   $filter->attributes(array('class'=>'form-inline'));
   $filter->add('title','Title', 'text');
   $filter->submit('search');
   $filter->reset('reset');

   $grid = DataGrid::source($filter);
   $grid->add('nome','Title', true);
   $grid->add('{{ substr($body,0,20) }}...','Body');
   $grid->paginate(10);

   View::make('articles', compact('filter', 'grid'))

```php # articles.blade {{ $filter }} {{ $grid }}, (*18)


[DataFilter explained](https://github.com/emiliosh/rapyd-laravel/wiki/DataFilter) [Custom layout and custom query scope](http://www.rapyd.com/rapyd-demo/customfilter) ## Install in Laravel 4.1 & 4.2 To `composer.json` add: `"emiliosh/rapyd": "1.3.*"` for both, not frequently updated (should be stable) `"emiliosh/rapyd": "dev-master"` for both, with latest stuffs (may be unstable) In `app/config/app.php` add: `'Emiliosh\Rapyd\RapydServiceProvider',` then run: `$ composer update emiliosh/rapyd`. ## Publish & override configuration (optional) You can quickly publish the configuration file (to override something) by running the following Artisan command. $ php artisan config:publish emiliosh/rapyd ## Publish & integrate assets (needed) You need to publish the assets from this package. $ php artisan asset:publish emiliosh/rapyd Note: The public assets can change overtime (because of upstream changes), it is recommended to re-publish them after update. Alternatively you can add the publish command in composer.json. "post-update-cmd": [ "php artisan asset:publish emiliosh/rapyd" ], You need also to add this to your views, to let rapyd add runtime assets: ```html <head> ... <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> {{ Rapyd::head() }} </head>

note: widget output is in standard with Boostrap 3+, and some widget need support of JQuery 1.9+ so be sure to include dependencies as above, (*19)

A better choice is to split css and javascipts and move javascript at bottom, just before body to speedup the page, you can do this with:, (*20)

<head>
  ...
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
{{ Rapyd::styles() }}
</head>
....

    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
   {{ Rapyd::scripts() }}
</body>

In short

Rapyd use a "widget" approach to make a crud, without "generation". (this approach is worst in terms of flexibility but fast/rapid in terms of development and maintenance):, (*21)

You need to "show" and "edit" record from an entity?
Ok so you need a DataGrid and DataEdit. You can build widgets where you want (even multiple widgets on same route). An easy way to work with rapyd is: * make a route to a controller for each entity you need to manage * make the controller with one method for each widget (i.e.: one for a datagrid and one for a dataedit) * make an empty view, include bootstrap and display content that rapyd will build for you, (*22)

Rapyd comes with demo (controller, models, views) to run it just add:, (*23)

/app/routes.php, (*24)

...
Route::controller('rapyd-demo', 'Emiliosh\\Rapyd\\Controllers\\DemoController');

then go to:, (*25)

/rapyd-demo, (*26)

or use the one that is online:
http://rapyd.com/rapyd-demo, (*27)

License

Rapyd is licensed under the MIT license, (*28)

If Rapyd saves you time, please support Rapyd, (*29)

The Versions

14/02 2018

dev-master

9999999-dev https://github.com/emiliosh/rapyd

crud widgets for laravel 4, to make an admin in few lines of code

  Sources   Download

The Requires

 

by Emilio Sosa

laravel form crud backend admin administrator datatable rapyd

28/07 2017

1.0

1.0.0.0 https://github.com/emiliosh/rapyd

crud widgets for laravel 4, to make an admin in few lines of code

  Sources   Download

The Requires

 

by Emilio Sosa

laravel form crud backend admin administrator datatable rapyd