Laravel Bash is a web application framework with expressive, elegant syntax. Routing, an ORM, templates, validation, queues, events and real-time broadcasting, built from the programs that are already installed on your server.
git clone https://github.com/mrstebo/laravel-bash.git && cd laravel-bash && ./sail up -d# routes/web.sh route GET /posts/{post} PostController::show route POST /orders/{order}/ship OrderController::ship # app/Http/Controllers/PostController.sh PostController::show() { local post comments post=$(Post::find "$1") || abort 404 comments=$(Comment::all | where post_id = "$1") view posts.show post="$post" comments="$comments" }
# Models run SQL. Everything after that is a pipe. Post::all \ | where status = published \ | withCount comments \ | orderBy votes desc \ | take 3 # take is head. Once it has 3 rows it exits, and # SIGPIPE stops the query. Lazy collections, free.
# app/Http/Requests/StorePostRequest.sh StorePostRequest::rules() { cat <<'RULES' title required|min:3|max:80 body required|min:20 status required|in:published,draft RULES } # app/Http/Controllers/PostController.sh PostController::store() { form_request StorePostRequest || { status 422; view posts.create; return; } validated data id=$(Post::create "${data[@]}") redirect "/posts/$id" }
# Three one-second calls. The page takes one second. DashboardController::index() { local -a results mapfile -d '' -t results < <( Concurrency::run count_posts count_comments fetch_weather ) view dashboard posts="${results[0]}" … }
# Anywhere in your app dispatch ProcessPodcast 42 # app/Jobs/ProcessPodcast.sh ProcessPodcast::handle() { local id=$1 … Log::info "Processed podcast $id" } # Four workers, one command ./artisan queue:work --workers=4
# app/Providers/EventServiceProvider.sh listen OrderShipped SendShipmentNotification # app/Http/Controllers/OrderController.sh OrderController::ship() { event OrderShipped order_id="$1" redirect /orders } # app/Events/OrderShipped.sh: it broadcasts OrderShipped::broadcastOn() { echo orders }
# routes/console.sh schedule inspire everyMinute schedule queue:retry hourly # The one line of cron you need. It was always Bash. * * * * * cd /var/www/html && ./artisan schedule:run
Why Laravel Bash
Laravel for PHP, Rust and Go each start with a programming language and build a framework inside it. Laravel Bash starts with the operating system. Every feature is a process, and Unix processes already know how to talk to each other: through output, exit codes, pipes, signals and files. So instead of writing a queue, we use mv. Instead of writing a WebSocket server, we use tail.
| In a programming language | In Laravel Bash |
|---|---|
| A function returns a value | A function prints to stdout, and $( ) catches it |
| Exceptions and try/catch | A non-zero exit code and a message on stderr. if ! catches it, and trap ERR is the handler |
| Method chaining on a collection | A pipeline. take 3 closes the pipe, and SIGPIPE stops the query |
| Threads, promises, async/await | & and wait -n. Each task is a real process, with its own memory |
| An event bus | kill -USR1 and trap |
| Redis, for queues | A folder, and mv |
| A WebSocket server | tail -F, as Server-Sent Events |
| A template engine | Heredocs |
| A garbage collector | The process exits at the end of the request |
| A package manager | apt-get, once, in the Dockerfile |
| A type system | Everything is a string. Quote it |
| A build step | None. Save the file and refresh |
The framework
A full-stack framework, made of small programs that each do one thing well.
Routes, parameters and controllers, matched with Bash's own regexes.
Query results as tab-separated lines, filtered, sorted and joined in a pipe.
Views are heredocs, so they're compiled before you write them. Output is escaped without a fork.
Laravel's rule strings, checked with builtins, with errors and old input for your forms.
Background jobs, a worker pool, timeouts, retries and a failed jobs folder.
Listeners that wake up the moment something happens, with nothing to poll.
Real-time updates in every open tab, with no WebSocket server to run.
Run slow things at the same time, and get the results back in order.
Scheduled commands that run on the minute and never overlap.
Migrations, tinker, route:list, the make commands, and ./artisan dev, which runs everything at once.
A test suite and a static analyser, run in CI on every push.
The whole stack in Docker Compose, with SQLite or Postgres, on any machine.
Proven technology
sort (1971), awk (1977) and Bash (1989) are all older than PHP (1995). These numbers were counted by the process that rendered this page.