All Projects → achillesp → laravel-crud-forms

achillesp / laravel-crud-forms

Licence: MIT License
Create CRUD Forms for Laravel Models.

Programming Languages

PHP
23972 projects - #3 most used programming language
Blade
752 projects

Projects that are alternatives of or similar to laravel-crud-forms

Watchable
Enable users to watch various models in your application.
Stars: ✭ 65 (+71.05%)
Mutual labels:  eloquent, laravel-5-package
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (+526.32%)
Mutual labels:  eloquent, laravel-5-package
Improved Polymorphic Eloquent Builder
🔨 Improved Polymorphic Eloquent Builder
Stars: ✭ 12 (-68.42%)
Mutual labels:  eloquent, laravel-5-package
Lada Cache
A Redis based, fully automated and scalable database cache layer for Laravel
Stars: ✭ 424 (+1015.79%)
Mutual labels:  eloquent, laravel-5-package
Angular5.2 Laravel5.6
Angular 5.2 and Laravel 5.6 Authentication and CRUD
Stars: ✭ 17 (-55.26%)
Mutual labels:  crud, laravel-5-package
Bouncer
Eloquent roles and abilities.
Stars: ✭ 2,763 (+7171.05%)
Mutual labels:  eloquent, laravel-5-package
Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (+421.05%)
Mutual labels:  eloquent, laravel-5-package
Evolutility Ui Jquery
Model-driven Web UI for CRUD using REST or localStorage.
Stars: ✭ 164 (+331.58%)
Mutual labels:  crud, forms
eloquent-mongodb-repository
Eloquent MongoDB Repository Implementation
Stars: ✭ 18 (-52.63%)
Mutual labels:  crud, eloquent
Forms Angular
Probably the most opinionated framework in the world
Stars: ✭ 412 (+984.21%)
Mutual labels:  crud, forms
Larrock Core
Core components for LarrockCMS
Stars: ✭ 46 (+21.05%)
Mutual labels:  crud, laravel-5-package
model-observers
Make model observers easy
Stars: ✭ 17 (-55.26%)
Mutual labels:  eloquent, laravel-5-package
laravel-mutate
Mutate Laravel attributes
Stars: ✭ 13 (-65.79%)
Mutual labels:  eloquent
laravel-garbage-man
Scheduled job to clean out Laravel's soft deleted records at configured interval
Stars: ✭ 33 (-13.16%)
Mutual labels:  laravel-5-package
Ajax-CRUD-example-in-laravel
Example performing CRUD operations in laravel using ajax.
Stars: ✭ 69 (+81.58%)
Mutual labels:  crud
DjangoReactTodo2
A simple CRUD Todo app with Token Authentication
Stars: ✭ 15 (-60.53%)
Mutual labels:  crud
ASP.NET-Core-2-MVC-CRUD-datatables-jQuery-Plugin
Asp.Net Example implementation of datatables.net using Asp.Net Core 2 Mvc CRUD datatables jQuery Plugin
Stars: ✭ 25 (-34.21%)
Mutual labels:  crud
node-wufoo
A Node.JS library for the Wufoo API.
Stars: ✭ 13 (-65.79%)
Mutual labels:  forms
laravel-autonumber
Laravel package to create autonumber for Eloquent model
Stars: ✭ 26 (-31.58%)
Mutual labels:  eloquent
servant-beam-realworld-example-app
Exemplary fullstack Medium.com clone powered by Servant and Beam
Stars: ✭ 33 (-13.16%)
Mutual labels:  crud

Laravel CRUD Forms

This is a Laravel >=5.5 package to help easily create CRUD (Create, Read, Update, Delete) forms for eloquent models (as well as an index page). It aims to be used as a quick tool which does not interfere with the other parts of the application that it's used in.

The package provides:

  • A trait to use in resource controllers and
  • A series of views for displaying the forms

The views are built using bootstrap (v3), but the styling can easily be overriden.

Installation

Composer

From the command line, run:

composer require achillesp/laravel-crud-forms

Configuration

This package uses a config file which you can override by publishing it to your app's config dir.

php artisan vendor:publish --provider=Achillesp\CrudForms\CrudFormsServiceProvider --tag=config

Usage

To use the package, you need to use the trait Achillesp\CrudForms\CrudForms in your model's controller and define your routes. The trait provides all the required methods for a Resource Controller, as well as a restore method in case of soft-deleted models.

Routes

If for example you have a Post model, you would define the routes:

Route::resource('/posts', 'PostController');

Controller

Then in your PostController, you will need to use the trait and also define a constructor where you give the needed details of the model.

use App\Post;
use Achillesp\CrudForms\CrudForms;

class PostController extends Controller
{
    use CrudForms;

    public function __construct(Post $post)
    {
        $this->model = $post;
    }
}

In the controller's constructor you can define the properties which are handled by the controller. The available properties that can be defined are as follows.

The model

This is the model, which should be passed in the constructor through Dependency Injection.

The formFields array

This is an array of all the fields you need in the forms. Each field is declared as an array that has:

  1. name: This is the model's attribute name, as it is in the database.
  2. label: This is the field's label in the forms.
  3. type: The type of the form input field that will be used. Accepted types are:
    • text
    • textarea
    • email
    • url
    • password
    • date
    • select
    • select_multiple
    • checkbox
    • checkbox_multiple
    • radio
  4. relationship: This is needed in case of a select, select_multiple, radio or checkbox_multiple buttons. You can state here the name of the relationship as it is defined in the model. In the example bellow, the Post model has a belongsTo relationship to category and a belongsToMany relationship to tags. For belongsTo relationships you can use a select or a radio(group of radios) input. For belongsToMany relationships you can use a select_multiple or checkbox_multiple inputs.
  5. relFieldName: This is optional. It is used only in case we have a relationship, to set the name of the attribute of the related model that is displayed (ie. in a select's options). If not defined, the default attribute to be used is name.
$this->formFields = [
    ['name' => 'title', 'label' => 'Title', 'type' => 'text'],
    ['name' => 'slug', 'label' => 'Slug', 'type' => 'text'],
    ['name' => 'body', 'label' => 'Enter your content here', 'type' => 'textarea'],
    ['name' => 'publish_on', 'label' => 'Publish Date', 'type' => 'date'],
    ['name' => 'published', 'label' => 'Published', 'type' => 'checkbox'],
    ['name' => 'category_id', 'label' => 'Category', 'type' => 'select', 'relationship' => 'category'],
    ['name' => 'tags', 'label' => 'Tags', 'type' => 'select_multiple', 'relationship' => 'tags'],
];

The indexFields array

These are the model's attributes that are displayed in the index page.

$this->indexFields = ['title', 'category_id', 'published'];

If not defined, then the first of the formFields is shown.

The formTitle (optional)

You can optionally, define the name of the model as we want it to appear in the views. If not defined, the name of the model will be used.

The bladeLayout (optional)

This is used to define the blade layout file that will be extended by the views for the crud forms and index page.

The option to display deleted models (withTrashed)

Setting this to true, will also display deleted models and offer an option to restore them.

$this->withTrashed = true;

In order to be able to restore the models, you need to define an additional route:

Route::put('/posts/{post}/restore', ['as' => 'posts.restore', 'uses' => 'PostController@restore']);

The validationRules array (optional)

These are the rules we want to use to validate data before saving the model.

$this->validationRules = [
    'title'       => 'required|max:255',
    'slug'        => 'required|max:100',
    'body'        => 'required',
    'publish_on'  => 'date',
    'published'   => 'boolean',
    'category_id' => 'required|int',
];

The validationMessages array (optional)

Use this to define custom messages for validation errors. For example:

$this->validationMessages = [
    'body.required' => "You need to fill in the post content."
];

The validationAttributes array (optional)

Use this to change the way an attribute's name should appear in validation error messages.

$this->validationAttributes = [
    'title' => 'Post title'
];

Views

The views are built with bootstrap v.3 and also have css classes to support some common JavaScript libraries.

  • select2 class is used in select inputs
  • datepicker class is used in date inputs
  • data-table class is used in the index view table

It is also possible to publish the views, so you can change them anyway you need. To publish them, use the following artisan command:

php artisan vendor:publish --provider=Achillesp\CrudForms\CrudFormsServiceProvider --tag=views

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].