Download the PHP package rutatiina/orchid-crud without Composer
On this page you can find all versions of the php package rutatiina/orchid-crud. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rutatiina/orchid-crud
More information about rutatiina/orchid-crud
Files in rutatiina/orchid-crud
Package orchid-crud
Short Description Build CRUD apps in fewer lines of code for Laravel Orchid.
License MIT
Homepage https://github.com/rutatiina/orchid-crud
Informations about the package orchid-crud
Introduction
Laravel Orchid has provided a unique experience for writing applications. Still, sometimes a simple CRUD needs to be done when it might seem overkill. Therefore, we have created a new package aimed at developers who want to quickly create a user interface for eloquent models with functions such as creating, reading, updating, and deleting.
You can describe the entire process using one file. And when you need more options, it's easy to switch to using the platform. All fields, filters, and traits are compatible.
Installation
The manual assumes that you already have a copy of Laravel with Orchid
You can install the package using the Сomposer. Run this at the command line:
This will update composer.json
and install the package into the vendor/
directory.
Defining Resources
Resources are stored in the app/Orchid/Resources
directory of your application.
You may generate a new resource using the orchid:resource
Artisan command:
The most fundamental property of a resource is its model
property.
This property tells the generator which Eloquent model the resource corresponds to:
These classes are completely static. They don't have any state at all due to their declarative nature. They only tell what to do. They don't hold any data. So if you add custom methods, make sure they're static.
Freshly created resources contain nothing. Don't worry. We'll add more fields to our resource soon.
Registering Resources
All resources within the app/Orchid/Resources
directory will automatically be registered by default.
You are not required to register them manually. But if this is required, for example, when creating an additional package, then the best way would be:
Expanding of Model
Many features of the Orchid platform relies on model customization. You can add or remove traits depending on your goals. But we will assume that you have set these for your model:
`
Defining Fields
Each resource contains a fields
method. This method returns an array of fields, which generally extend the Orchid\Screen\Field
class. To add a field to a resource, we can add it to the resource's fields
method. Typically, fields may be created using their static make
method. This method accepts several arguments; however, you usually only need to pass the field's name.
In the package to generate CRUD, you can use the fields Orchid platform. Review all available fields on the documentation site.
Defining Сolumns
Each resource contains a сolumns
method. To add a column to a resource, we can add it to the resource's column
method. Typically, columns may be created using their static make
method.
The CRUD generation package is entirely based on the table layer. You can read more about this on the documentation page.
Defining Legend
Each resource contains a legend
method. It determines how the model will look when viewed. To add to a resource, we can add it to the resource's legend
method. Typically, columns may be created using their static make
method.
The CRUD generation package is entirely based on the legend layer. You can read more about this on the documentation page.
Defining Rules
Each resource contains a rules
method. When submitting a create or update form, the data can be validated, which is described in the rules
method:
You can learn more on the Laravel validation page.
Defining Filters
Each resource contains a filters
method. Which expects you to return a list of class names that should be rendered and, if necessary, swapped out for the viewed model.
To create a new filter, there is a command:
This will create a class filter in the app/Http/Filters
folder. To use filters in your own resource, you need:
We already offer some prepared filters:
Orchid\Crud\Filters\DefaultSorted
- Setting default column sortingOrchid\Crud\Filters\WithTrashed
- To display deleted records
You can learn more on the Orchid filtration page.
Navigation
If you do not want a resource to appear in the navigation, you may override the displayInNavigation
method of your resource class:
Eager Loading
Suppose you routinely need to access a resource's relationships within your fields. In that case, it may be a good idea to add the relationship to the with
property of your resource. This property instructs to always eager to load the listed relationships when retrieving the resource.
Pagination
To define how many results should be shown per page, set the perPage
method:
Resource Events
Each resource has two methods that do the processing, onSave
and onDelete
. Each of them is launched when the event is executed, and you can change or supplement the logic:
Permissions Resources
Each resource contains a permission
method, which should return the string key that the user needs to access this resource. By default, all resources are available to every user.
For each registered resource in which the method returns a non-null value, a new permission is created.
It is necessary to give the right to manage it to the user. To click on the profile in the left column, go to the system page, and then to the page with users, you can issue them a mandate or assign a role. After that, they will be displayed in the left menu.
Actions
Actions may be generated using the orchid:action
Artisan command:
By default, all actions are placed in the app/Orchid/Actions
directory. The action necessarily consists of two methods. Method button
defines name, icon, dialog box, etc. And the handler
method directly handles the action with the models.
Within the handle
method, you may perform whatever tasks are necessary to complete the action.
The handle method always receives a
Collection
of models, even if the action is only being performed against a single model.
Once you have defined an action, you are ready to attach it to a resource. Each resource contains an actions method. To attach an action to a resource, you should add it to the array of actions returned by this method:
Policies
To limit which users may view, create, update, or delete resources leverages Laravel's authorization policies. Policies are simple PHP classes that organize authorization logic for a particular model or resource. For example, if your application is a blog, you may have a Post
model and a corresponding PostPolicy
within your application.
Typically, these policies will be registered in your application's AuthServiceProvider
. If CRUD detects a policy has been registered for the model, it will automatically check that policy's relevant authorization methods before performing their respective actions, such as:
- viewAny
- view
- create
- update
- delete
- restore
- forceDelete
No additional configuration is required! So, for example, to determine which users are allowed to update a Post
model, you need to define an update
method on the model's corresponding policy class:
If a policy exists but is missing a particular action method, the user will not be allowed to perform that action. So, if you have defined a policy, don't forget to define all of its relevant authorization methods.
If you don't want the policy to affect CRUD generation users, you may wish to authorize all actions within a given policy. To accomplish this, define a before
method on the policy. Before any other policy methods, the before method will be executed, allowing you to authorize the action before the intended policy method is actually called.
Preventing Conflicts (Traffic Cop)
If this option is active, the model will be checked for the last change if it was updated after the edit form was opened. A validation error will be thrown. Feature Traffic Cop is disabled by default.
Description
To display an additional description on each page of the resource, use the description
:
Breadcrumbs
On every page of the resource, there are breadcrumbs. You can monitor messages using the following methods:
Localization
Resource names may be localized by overriding the label
and singularLabel
methods on the resource class:
Action buttons and notifications can also be translated, for example:
You can learn more on the Laravel localization page.
Backers
Thank you to all our backers! 🙏 [Become a backer]
Roadmap
This roadmap isn't meant to cover everything we're going to work on. We will continue to invest in making CRUD easier to use and easier to manage. We want to do:
- [x] Add setting for displaying and restoring deleted models with
Illuminate\Database\Eloquent\SoftDeletes
; - [x] Add the ability to perform actions for multiple models;
- [ ] Support of nested relations when viewing
It is an active community, so expect more contributions that will complement it with all sorts of other improvements to help improve production.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Communication Channels
You can find help and discussion in the following places:
- Start a new discussion https://github.com/orchidsoftware/platform/discussions/new
- Create issue https://github.com/orchidsoftware/crud/issues/new
- Telegram chat (EN)
- Telegram chat (RU)
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
Please see License File for more information.