2017 © Pedro Peláez
 

plugin laravel-crudable

Laravel CRUD builder powered by custom fields

image

marceauka/laravel-crudable

Laravel CRUD builder powered by custom fields

  • Saturday, January 28, 2017
  • by MarceauKa
  • Repository
  • 7 Watchers
  • 34 Stars
  • 139 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

Laravel Crudable

Build Status Scrutinizer Code Quality, (*1)

Laravel Crudable is a library built to bring Custom Fields powered CRUD functionnalities to your Eloquent models., (*2)

Summary

A step by step tutorial for beginners is available here: Beginner Guide (also available as a 3 min video)., (*3)

Goals

  • Easy to integrate on a new project
  • Easy to integrate to an existing project
  • Non-intrusive API (just add a trait and one method to your model)
  • Focus on fields
  • Customizable
  • Laravel's way

Non-goals

  • Roles or permissions
  • Admin panel

Installation

This version is compatible with Laravel 5.4 and 5.3. For Laravel 5.2 compatibility see the branch 1.0., (*4)

Install via composer:, (*5)

composer require marceauka/laravel-crudable

Then register the service provider in your config/app.php., (*6)

// After other service providers
Akibatech\Crud\CrudServiceProvider::class

Finally, publish resources:, (*7)

php artisan vendor:publish --tag=crud

This command will publish language files and views for easy customization., (*8)

Usage

Add the trait Crudable to your Eloquent Model, then implement the required method getCrudFields, (*9)

Example model:, (*10)

class Post extends Model
{
    use Crudable;

    /**
     * @return \Akibatech\Crud\Services\CrudFields
     */
    public function getCrudFields()
    {
        return CrudFields::make([
            // Bind the title attribute to a required Text Field.
            TextField::handle('title', 'required|min:3')->withPlaceholder('Title of the post'),

            // Bind the introduction attribute to a required Textarea Field.
            TextareaField::handle('introduction', 'required|min:3')->withPlaceholder('Short introduction'),

            // Bind the content attribute to a Tinymce Field
            TinymceField::handle('content', 'required'),

            // Bind the illustration attribute to a file upload allowing 10Mb JPG or PNG picture
            FileUploadField::handle('illustration')->withMaxSize(1024 * 1024)->withTypes('jpeg,png'),

            // Bind the status attribute to a Radio Field allowing Draft or Live options.
            RadioField::handle('status', 'required')->withOptions([0 => 'Draft', 1 => 'Live'])
        ]);
    }
}

Display the table of entries

In your controller:, (*11)

    public function index()
    {
        $model = App\Post::class;

        return view('your-view', compact($model));
    }

In your view:, (*12)

@crudtable($model)

Learn more: The Table, (*13)

Entry table, (*14)

Display the entry create form

In your controller:, (*15)

    public function create()
    {
        $model = App\Post::class;

        return view('your-view', compact($model));
    }

    public function store(Request $request)
    {
        $entry = (new App\Post)->crudEntry();
        $validation = $entry->validate($request->all());

        if ($validation->passes())
        {
            $validation->save();
        }

        // Redirect to the form with the errors if validation fails, or to the index page  
        return $validation->redirect();
    }

In your view:, (*16)

@crudentry($model)

Learn more: The Entry, (*17)

Entry form, (*18)

Fields

Fields are the way to bind your model attributes to powerful behaviors and reusable view components., (*19)

At this stage, you can use TextField, TextareaField, RadioField, EmailField, TinymceField, FileUploadField, SelectRelationField and DatePickerField, but many others are planned., (*20)

Lean more: Fields, (*21)

Controller and routes

By default each crudded model needs a Controller., (*22)

You can scaffold it with the command make:crud:controller <controller-name> <model-name>.
Ex: artisan make:crud:controller PostsController Post., (*23)

This command will generate a CRUD ready controller for your model with some scaffolded views but it's up to you to customize them., (*24)

Once generated, your need to register routes like this:, (*25)

// routes/web.php
App\Post::crudRoutes();

Learn more: Routes and controlllers, (*26)

Customizing

All views are customizable and are stored in resources/views/vendor/crud., (*27)

Complete documentation: Customize Views, (*28)

Tests

You can launch tests with, (*29)

vendor/bin/phpunit

Contribute

Feel free to contribute using issues and pull requests on this repo., (*30)

Authors

Licence

The MIT License (MIT) Copyright (c) 2016 Marceau Casals, (*31)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*32)

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*33)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*34)

The Versions

28/01 2017

1.0.x-dev

1.0.9999999.9999999-dev

Laravel CRUD builder powered by custom fields

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel crud admin fields

28/01 2017

1.0.5

1.0.5.0

Laravel CRUD builder powered by custom fields

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel crud admin fields

28/01 2017

dev-master

9999999-dev

Laravel CRUD builder powered by custom fields

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel crud admin fields

28/01 2017

dev-develop

dev-develop

Laravel CRUD builder powered by custom fields

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel crud admin fields

28/01 2017

2.0.2

2.0.2.0

Laravel CRUD builder powered by custom fields

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel crud admin fields