Expose the signed-in user and other request context to a view Engine

Open
#787 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Start by reading Template and the Engine extension point, then inspect how request context is made available to views. The issue identifies signed-in user access as a concrete gap; the broader request, authorization, config, translation, and clock APIs need a design decision. Done means agreeing on the supported context API and exposing the selected data to engines.

Written by the indexing model from the issue text.

Description

I built an external Blade engine on top of laravel::view::Engine (https://github.com/RicardoAugustoTulio/laravel-rust-blade) to ease migrating Laravel PHP apps. The extension point worked without framework changes, including a multi-dot extension (engine("blade.php", ..)) next to MiniJinja .html views. A few things an Engine can't reach, so the crate works around them:

  1. Named routes. Already reported in #784. I'd use the same route_named lookup.
  2. The signed-in user. @auth and @guest have to read the session value under the literal key "_auth.web.id". USER_ID_KEY (crates/http/src/session/mod.rs) isn't re-exported by laravel, so the engine depends on that spelling. Either pub use the constant from laravel::session, or add Template::user_id() -> Option<...>.
  3. Request, authorization, config, translations, clock. Nothing on Template gives an engine the request (request()->is(..)), @can checks, config values or translated strings. The crate fails these at compile time with a message, and lets the application register its own function. If a small read-only handle (for example the request's path and query, or a way to run a policy check) is welcome on Template, I can propose the shape in a PR. If not, the current workaround is fine.

The engine's other framework notes are in https://github.com/RicardoAugustoTulio/laravel-rust-blade/blob/master/docs/FRAMEWORK.md.

Seen on 0.x. Happy to send a PR for 2 if the approach is welcome.

Dominant language
Rust
Stars
847
Forks
174
Avg merge
5h 40m
Merged PRs (30d)
167

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from laravel/rust-framework

All issues in laravel/rust-framework

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.