use laravel::container::{Container, Registrar};
use laravel::foundation::ServiceProvider;
use crate::registry;
#[derive(Debug, Clone, Default)]
pub struct LaractionsServiceProvider {
migrations: bool,
}
impl LaractionsServiceProvider {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_migrations(mut self) -> Self {
self.migrations = true;
self
}
}
impl ServiceProvider for LaractionsServiceProvider {
fn register(&self, app: &mut Registrar) {
app.discover(env!("CARGO_CRATE_NAME"));
if self.migrations {
app.migrations().add(laravel::db::migrations!("database/migrations"));
}
}
async fn boot(&self, _app: &Container) -> laravel::Result<()> {
registry::check_names().map_err(|message| laravel::Error::msg(message))
}
}