laravel-rust-admin 0.1.0

Admin panel framework for Laravel for Rust: auto-generated CRUD tables, forms, actions, and dashboard widgets from your models.
Documentation
//! The four places where the panel reaches past Laravel's documented API.
//!
//! `#[model]` gives each model its own `query`, `create`, `update`, and `delete` methods. They
//! are inherent methods of each struct, so code that only knows `M: Model`, as the panel does,
//! can't call them. What it can call is what those methods are made of: the functions and
//! builders that `#[model]` expands to, which `laravel::model` exports without documenting.
//!
//! Laravel makes no promise to keep those the same from one release to the next. They are all
//! used here and nowhere else, so that a change in them is a change to this file.

use laravel::db::Builder;
use laravel::model::{__delete, __query, CreateBuilder, Fill, Model, UpdateBuilder};

/// A new query of the model, as `Post::query()` returns.
pub(crate) fn query<M: Model>() -> Builder<M> {
    __query()
}

/// Creates a model from an input struct, as `create!(Post { ..input })` does.
pub(crate) async fn create<M: Model>(input: impl Fill<M>) -> laravel::Result<M> {
    CreateBuilder::<M>::new().fill(input).await
}

/// Updates a model from an input struct, as `update!(post { ..input })` does.
pub(crate) async fn update<M: Model>(model: &mut M, input: impl Fill<M>) -> laravel::Result<()> {
    UpdateBuilder::new(model).fill(input).await
}

/// Deletes a model, as `post.delete()` does.
pub(crate) async fn delete<M: Model>(model: M) -> laravel::Result<()> {
    __delete(model).await
}