Download the PHP package achillesp/laravel-crud-forms without Composer
On this page you can find all versions of the php package achillesp/laravel-crud-forms. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-crud-forms
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:
Configuration
This package uses a config file which you can override by publishing it to your app's config dir.
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:
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.
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:
name
: This is the model's attribute name, as it is in the database.label
: This is the field's label in the forms.type
: The type of the form input field that will be used. Accepted types are:- text
- textarea
- url
- password
- date
- select
- select_multiple
- checkbox
- checkbox_multiple
- radio
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, thePost
model has abelongsTo
relationship tocategory
and abelongsToMany
relationship totags
. ForbelongsTo
relationships you can use a select or a radio(group of radios) input. ForbelongsToMany
relationships you can use a select_multiple or checkbox_multiple inputs.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 isname
.
The indexFields
array
These are the model's attributes that are displayed in the index page.
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.
In order to be able to restore the models, you need to define an additional route:
The validationRules
array (optional)
These are the rules we want to use to validate data before saving the model.
The validationMessages
array (optional)
Use this to define custom messages for validation errors. For example:
The validationAttributes
array (optional)
Use this to change the way an attribute's name should appear in validation error messages.
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:
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-crud-forms with dependencies
illuminate/config Version ~10.0
illuminate/database Version ~10.0
illuminate/http Version ~10.0