laravel-rust-admin 0.1.1

Admin panel framework for Laravel for Rust: auto-generated CRUD tables, forms, actions, and dashboard widgets from your models.
Documentation
//! An admin panel for [Laravel for Rust](https://laravel.com/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:
//!
//! ```ignore
//! 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`:
//!
//! ```ignore
//! 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`](AdminPanel::middleware) nor an
//! [`authorize`](AdminPanel::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.

#![warn(missing_docs)]

pub mod config;
pub mod http;
mod model;
pub mod panel;
pub mod protocol;
pub mod resource;
pub mod schema;
pub mod widget;

pub use config::{AccentColor, AdminConfig};
pub use laravel_rust_admin_macros::AdminResource;
pub use panel::{AdminPanel, AdminUser, PanelState, RequestFn};
pub use protocol::{BadgeColor, ChartStyle, ColumnAlign, ColumnKind, FieldKind, SortDirection, TrendDirection};
pub use resource::{AdminResource, NavigationBadge, ReadOnly, ResourceInput};
pub use schema::{
    ActionConfirmation, ActionContext, ActionOutcome, BulkAction, Column, Field, Filter, FormBuilder, FormSection,
    RowAction, SelectOption, TableBuilder, TableTab,
};
pub use widget::{ChartWidget, DashboardWidget, StatWidget, TableWidget};

/// Convenient imports for defining admin resources, widgets, and panels.
pub mod prelude {
    pub use crate::{
        AccentColor, ActionConfirmation, ActionContext, ActionOutcome, AdminPanel, AdminResource, AdminUser,
        BadgeColor, BulkAction, ChartStyle, ChartWidget, Column, ColumnAlign, DashboardWidget, Field, Filter,
        FormBuilder, FormSection, NavigationBadge, ReadOnly, RowAction, SelectOption, SortDirection, StatWidget,
        TableBuilder, TableTab, TableWidget, TrendDirection,
    };
}