Expand description
An admin panel for Laravel for Rust applications.
Describe your models as resources, add the panel’s service provider, and your application
serves a back office at /admin: a table for each model with search, filters, tabs, sorting,
and CSV export, forms that create and edit records, your own actions on one record or on many,
a dashboard, and a command palette that searches everything. The panel’s frontend is built
into the crate, so the application needs no Node toolchain.
§A resource from a model
The quickest resource is a derive on the model. The table and the form come from its fields, and the inputs you name say what the panel may write:
use laravel::model::model;
use laravel::time::Timestamp;
use laravel_rust_admin::AdminResource;
#[model]
#[derive(AdminResource)]
#[admin(icon = "users", create = StoreCustomer, update = StoreCustomer)]
pub struct Customer {
pub id: i64,
pub name: String,
pub email: String,
pub created_at: Timestamp,
pub updated_at: Timestamp,
}
#[laravel::input(fills = Customer)]
#[validate(authenticated)]
pub struct StoreCustomer {
#[validate(required, max_length(120))]
pub name: String,
#[validate(required, email)]
pub email: String,
}The panel creates and updates records only through those input structs. Their validation rules run on every save, their messages appear under the form’s fields, and a field the struct doesn’t declare can’t be written, whatever the browser sends.
For a table with tabs, a column from a relationship, actions, or authorization, implement
AdminResource by hand instead.
§The panel
AdminPanel is a service provider. Give it the resources, say who may enter, and add it in
src/app.rs:
use laravel::Application;
use laravel::auth::Authenticate;
use laravel::http::Request;
use laravel_rust_admin::AdminPanel;
async fn admins_only(request: &Request) -> laravel::Result<bool> {
Ok(request.user::<User>().await?.is_some_and(|user| user.is_admin))
}
Application::configure()
.with_providers(|providers| {
providers.add(
AdminPanel::new()
.brand("Acme")
.middleware(Authenticate)
.authorize(admins_only)
.resource::<Customer>()
.resource::<OrderResource>(),
);
})A panel with neither middleware nor an
authorize gate would be open to anyone who finds its URL. Such a
panel only answers in the local and testing environments. Everywhere else it responds
with a 403 until you add one of the two.
§Cargo features
The panel uses whichever database driver your application enables on laravel-rust, so an
application needs none of this crate’s features. sqlite, postgres, and mysql only exist
to build the crate by itself, as its own tests do.
Re-exports§
pub use config::AccentColor;pub use config::AdminConfig;pub use panel::AdminPanel;pub use panel::AdminUser;pub use panel::PanelState;pub use panel::RequestFn;pub use protocol::BadgeColor;pub use protocol::ChartStyle;pub use protocol::ColumnAlign;pub use protocol::ColumnKind;pub use protocol::FieldKind;pub use protocol::SortDirection;pub use protocol::TrendDirection;pub use resource::AdminResource;pub use resource::ReadOnly;pub use resource::ResourceInput;pub use schema::ActionConfirmation;pub use schema::ActionContext;pub use schema::ActionOutcome;pub use schema::BulkAction;pub use schema::Column;pub use schema::Field;pub use schema::Filter;pub use schema::FormBuilder;pub use schema::FormSection;pub use schema::RowAction;pub use schema::SelectOption;pub use schema::TableBuilder;pub use schema::TableTab;pub use widget::ChartWidget;pub use widget::DashboardWidget;pub use widget::StatWidget;pub use widget::TableWidget;
Modules§
- config
- Configuration section for
laravel-rust-admin. - http
- HTTP routing, middleware, and JSON/HTML handlers for the admin panel.
- panel
AdminPanelbuilder andlaravel::foundation::ServiceProviderintegration.- prelude
- Convenient imports for defining admin resources, widgets, and panels.
- protocol
- What the panel’s server and its browser app say to each other: every request and response body of the panel’s JSON API.
- resource
- The
AdminResourcetrait, and the code that serves a resource’s table, form, search, and export from it. - schema
- Fluent builders for admin tables, forms, filters, tabs, and actions.
- widget
- What the dashboard shows: stats, charts, and short tables.
Derive Macros§
- Admin
Resource - Makes a
#[model]struct an admin resource, with a table and a form built from its fields.