1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! 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.
pub use ;
pub use AdminResource;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Convenient imports for defining admin resources, widgets, and panels.