Skip to content

Starter Kits

David Ciulla edited this page Nov 7, 2026 · 1 revision

Starter Kits

Laravex ships three opt-in starter kits that scaffold boilerplate for common features. All are invoked via Artisan's install:* commands, implemented in Laravex.Install.

install:api

Scaffolds a minimal API layer with bearer-token authentication.

./artisan install:api
./artisan migrate

What it creates:

  • routes/api.ex — Registers a GET /api/user route under the api middleware group that authenticates via a bearer token and returns the user's id, email, and name as JSON (or 401 if unauthenticated).

Route group:

Router.group([prefix: "api", middleware: ["api"]], fn ->
  Router.get("/user", fn request ->
    user =
      case Laravex.Http.Request.bearer_token(request) do
        nil   -> nil
        token -> Laravex.Auth.Token.find_user(token)
      end

    if user do
      Laravex.Http.Response.json(%{id: user.id, email: user.email, name: user.name})
    else
      Laravex.Http.Response.json(%{message: "Unauthenticated."}, 401)
    end
  end)
end)

The routes/api.ex module is auto-registered on application boot once compiled. The api middleware group applies ThrottleRequests and SubstituteBindings (no session or CSRF).

After migrating, issue a token in IEx or a seeder:

token = Laravex.Auth.Token.create(user, "my-app", ["*"])
plain = token["plainTextToken"]

Send it with every API request:

Authorization: Bearer <plain-token>

See API-Tokens for the full token API.

install:broadcasting

Scaffolds the broadcasting channel authorization layer.

./artisan install:broadcasting

What it creates:

  • routes/channels.ex — Channel authorization file (equivalent to Laravel's routes/channels.php)
  • config/broadcasting.exs — Broadcasting driver configuration

routes/channels.ex:

defmodule Routes.Channels do
  def register do
    Laravex.Broadcasting.Channel.channel(
      "App.Models.User.{id}",
      fn user, %{"id" => id} ->
        not is_nil(user) and to_string(user.id) == to_string(id)
      end
    )

    :ok
  end
end

config/broadcasting.exs:

%{
  "default"     => Laravex.Env.get("BROADCAST_CONNECTION", "log"),
  "connections" => %{
    "log"    => %{"driver" => "log"},
    "null"   => %{"driver" => "null"},
    "reverb" => %{"driver" => "reverb"},
    "pusher" => %{"driver" => "pusher"},
    "ably"   => %{"driver" => "ably"}
  }
}

Set BROADCAST_CONNECTION in .env to switch drivers.

install:starter-kit

Scaffolds a complete session-based authentication flow with login, forgot password, and reset password.

./artisan install:starter-kit
./artisan migrate

What it creates:

Path Description
resources/views/auth/login.blade.php Login form with remember-me checkbox
resources/views/auth/forgot_password.blade.php Forgot password form
resources/views/auth/reset_password.blade.php Reset password form
app/Http/Controllers/auth_controller.ex App.Http.Controllers.AuthController
routes/auth.ex Auth routes registered as Routes.Auth

Routes registered (routes/auth.ex):

Method Path Name Action
GET /login login Show login form
POST /login — Attempt login
POST /logout — Logout
GET /forgot-password password.request Show forgot form
POST /forgot-password password.email Send reset link
GET /reset-password/{token} password.reset Show reset form
POST /reset-password password.update Process reset

AuthController highlights:

  • login/1 calls Laravex.Auth.Guard.attempt/2; on success redirects to /, on failure re-flashes errors — see Authentication
  • send_reset/1 calls Laravex.Auth.Password.send_reset_link/1 — see Passwords
  • reset/1 calls Laravex.Auth.Password.reset/1 and validates with required|confirmed|min:8

Routes.Auth is auto-discovered and registered by Laravex.Foundation.Application.register_http_routes/1.

See Also

  • Authentication — Guard, session, and middleware details
  • API-Tokens — install:api and bearer token lifecycle
  • Passwords — install:starter-kit reset-password flow

Clone this wiki locally