This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Wahyu Kristianto
Many ask what is the difference between Laravel and Lumen. Here is my answer on StackOverflow:
Apr 15 '15
Comments: 4
Answers: 8
194
I read the documentation and it seems Lumen is Laravel with less features. I must be missing something.
I am looking for a comparison table of the components and features of both Laravel and Lumen. Does anyone know the differences?
Routing
Basic
Features |
Laravel |
Lumen |
GET |
Route::get($uri, $callback) |
$router->get($uri, $callback) |
POST |
Route::post($uri, $callback) |
$router->post($uri, $callback) |
PUT |
Route::put($uri, $callback) |
$router->put($uri, $callback) |
PATCH |
Route::patch($uri, $callback) |
$router->patch($uri, $callback) |
DELETE |
Route::delete($uri, $callback) |
$router->delete($uri, $callback) |
OPTION |
Route::option($uri, $callback) |
$router->option($uri, $callback) |
Multiple HTTP verbs |
Route::match($types, $uri, $callback) |
 |
All HTTP verbs |
Route::any($uri, $callback) |
 |
Redirect Routes
Features |
Laravel |
Lumen |
Basic |
Route::redirect($from, $to, $status); |
 |
Premanent |
Route::permanentRedirect($from, $to); |
 |
View Routes
Features |
Laravel |
Lumen |
Basic |
Route::view($from, $to); |
 |
Route Parameters
Features |
Laravel |
Lumen |
Parameters |
 |
 |
Parameters & Dependency Injection |
 |
 |
Required Parameters |
 |
 |
Required Parameters |
 |
 |
Regular Expression Constraints |
 |
 |
Global Constraints |
 |
 |
Named Routes
Features |
Laravel |
Lumen |
Basic |
Route::get($uri, $callback)->name('profile') |
$router->get($uri, ['as' => 'profile', $callback]) |
Generating URLs To Named Routes |
route('profile') |
route('profile') |
Inspecting The Current Route by Name |
$request->route()->named('profile') boolean |
 |
Route Groups
Features |
Laravel |
Lumen |
Middleware |
Route::middleware($middleware) |
$router->group(['middleware' => $middleware], $callback) |
Controllers |
Route::controller(ProfileController::class) |
 |
Subdomain Routing |
Route::domain('{account}.example.com') |
 |
Namespaces |
Route::namespace($namespace) |
$router->group(['namespace' => $namespace], $callback) |
Route Prefixes |
Route::prefix('admin') |
$router->group(['prefix' => 'admin'], $callback) |
Route Name Prefixes |
Route::name('admin.') |
 |
Route Model Binding
Features |
Laravel |
Lumen |
Implicit Binding |
 |
 |
Implicit Enum Binding |
 |
 |
Explicit Binding |
 |
 |
Fallback Routes
Features |
Laravel |
Lumen |
Basic |
Route::fallback() |
 |
Route Caching
Features |
Laravel |
Lumen |
Basic |
 |
 |
Middleware
Features |
Laravel |
Lumen |
Defining Middleware |
artisan make:middleware |
Manual |
Global Middleware |
 |
 |
Assigning Middleware To Routes |
 |
 |
Middleware Groups |
 |
 |
Middleware Parameters |
 |
 |
Terminable Middleware |
 |
 |
CSRF Protection
Features |
Laravel |
Lumen |
Basic |
 |
 |
CSRF removed since Lumen version 5.2
Controllers
Features |
Laravel |
Lumen |
Defining Controller |
artisan make:controller |
Manual |
Basic |
 |
 |
Single Action Controllers |
 |
 |
Controller Middleware |
 |
 |
Resource Controllers |
 |
 |
Dependency Injection & Controllers |
 |
 |
Requests
Features |
Laravel |
Lumen |
Accessing The Request |
 |
 |
Request Path & Method |
 |
 |
Request Headers |
 |
 |
Request IP Address |
 |
 |
Content Negotiation |
 |
 |
PSR-7 Requests |
 |
 |
Retrieving Input |
 |
 |
Determining If Input Is Present |
 |
 |
Merging Additional Input |
 |
 |
Old Input |
 |
 |
Cookies |
 |
 |
Input Trimming & Normalization |
 |
 |
Retrieving Uploaded Files |
 |
 |
Moving Uploaded Files |
 |
 |
Response
Features |
Laravel |
Lumen |
Attaching Headers To Responses |
 |
 |
Attaching Cookies To Responses |
 |
 |
Redirects |
 |
 |
View Responses |
 |
 |
JSON Responses |
 |
 |
File Downloads |
 |
 |
File Responses |
 |
 |
Views & Blade
Features |
Laravel |
Lumen |
Basic |
 |
 |
Blade |
 |
 |
Session
Features |
Laravel |
Lumen |
Basic |
 |
 |
Session removed since Lumen version 5.2
Validation
Features |
Laravel |
Lumen |
Basic |
 |
 |
Form Requests |
 |
 |
The $this->validate Method |
 |
The $this->validate helper which is available in Lumen will always return a JSON response with the relevant error messages. This is in contrast to the Laravel version of the method which will return a redirect response if the request is not an AJAX request. Since Lumen is stateless and does not support sessions, flashing errors to the session is not a possibility. Unlike Laravel, Lumen provides access to the validate method from within Route closures. |
The exists And unique Rules |
 |
If you would like to use the exists or unique validation rules, you should uncomment the $app->withEloquent() method call in your bootstrap/app.php file. |
The $errors View Variable |
 |
Lumen does not support sessions out of the box, so the $errors view variable that is available in every view in Laravel is not available in Lumen. Should validation fail, the $this->validate helper will throw Illuminate\Validation\ValidationException with embedded JSON response that includes all relevant error messages. |
Errors & Logging
Features |
Laravel |
Lumen |
Error |
 |
 |
Logging |
 |
 |
Artisan Console
Features |
Laravel |
Lumen |
Running Commands |
 |
 |
Writing Commands |
 |
 |
Cache
Features |
Laravel |
Lumen |
Basic |
 |
 |
Before using the Cache
facade, be sure you have uncommented the $app->withFacades()
method call in your bootstrap/app.php
file.
Redis Support
Before using a Redis cache with Lumen, you will need to install the illuminate/redis
package via Composer. Then, you should register the Illuminate\Redis\RedisServiceProvider
in your bootstrap/app.php
file:
$app->register(Illuminate\Redis\RedisServiceProvider::class);
If you have not called $app->withEloquent()
in your bootstrap/app.php
file, then you should call $app->configure('database');
in the bootstrap/app.php
file to ensure the Redis database configuration is properly loaded.
Compiling Assets
Features |
Laravel |
Lumen |
Mix |
 |
 |
Events
Features |
Laravel |
Lumen |
Basic |
 |
 |
Generators
In Lumen, there are no generator commands to generate events and listeners for you, so you should simply copy the ExampleEvent
or ExampleListener
classes to define your own events and listeners. These example classes provide the basic structure of every event and listener.
Registering Events / Listeners
Like the full Laravel framework, the EventServiceProvider
included with your Lumen application provides a convenient place to register all event listeners. The listen
property contains an array of all events (keys) and their listeners (values). Of course, you may add as many events to this array as your application requires:
protected $listen = [
'App\Events\ExampleEvent' => [
'App\Listeners\ExampleListener',
],
];
Firing Events
You may use the event
helper function or Event
facade to fire events throughout your Lumen application. Again, these functions behave exactly like their full Laravel framework equivalent:
event(new ExampleEvent);
Event::dispatch(new ExampleEvent);
Authentication & Authorization
Features |
Laravel |
Lumen |
Authentication |
 |
 |
Authorization |
 |
 |
Authentication
Authentication in Lumen, while using the same underlying libraries as Laravel, is configured quite differently from the full Laravel framework. Since Lumen does not support session state, incoming requests that you wish to authenticate must be authenticated via a stateless mechanism such as API tokens.
Authorization
Defining Abilities
The primary difference when using authorization in Lumen compared to Laravel is in regards to how abilities are defined. In Lumen, you may simply use the Gate
facade in your AuthServiceProvider
to define abilities:
Gate::define('update-post', function ($user, $post) {
return $user->id === $post->user_id;
});
Defining Policies
Unlike Laravel, Lumen does not have a $policies
array on its AuthServiceProvider
. However, you may still call the policy
method on the Gate
facade from within the provider's boot
method:
Gate::policy(Post::class, PostPolicy::class);
Checking Abilities
You may "check" abilities just as you would in the full Laravel framework. First, you may use the Gate
facade. If you choose to use the facade, be sure to enable facades in your bootstrap/app.php
file. Remember, we don't need to pass the User
instance into the allows
method since the currently authenticated user will automatically be passed to your authorization callback:
if (Gate::allows('update-post', $post)) {
//
}
if (Gate::denies('update-post', $post)) {
abort(403);
}
Of course, you may also check if a given User
instance has a given ability:
if ($request->user()->can('update-post', $post)) {
// The user is allowed to update the post...
}
if ($request->user()->cannot('update-post', $post)) {
abort(403);
}
Database
Features |
Laravel |
Lumen |
Basic Queries |
 |
 |
Query Builder |
 |
 |
Eloquent ORM |
 |
 |
Migrations |
 |
 |
Seeders |
 |
 |
If you would like to use the DB
facade, you should uncomment the $app->withFacades()
call in your bootstrap/app.php
file.
Email Verification & Resetting Passwords
Features |
Laravel |
Lumen |
Email Verification |
 |
 |
Resetting Passwords |
 |
 |
Encryption & Hashing
Features |
Laravel |
Lumen |
Encryption |
 |
 |
Hashing |
 |
 |
You should set the APP_KEY
option of your .env
file to a 32 character, random string. If this value is not properly set, all values encrypted by Lumen will be insecure.
Mail
Features |
Laravel |
Lumen |
Basic |
 |
 |
Queues
Features |
Laravel |
Lumen |
Basic |
 |
 |
Closure jobs are not supported by Lumen.
Generators
Lumen does not include generators for automatically creating new Job classes. Instead, you should copy the ExampleJob
class that is included with the framework.
Dispatching Jobs
Again, you should consult the full Laravel queue documentation for complete information on dispatching queued jobs; however, just like in the Laravel framework, you may use the dispatch
function to dispatch jobs from anywhere within your Lumen application:
dispatch(new ExampleJob);
Of course, you may also use the Queue
facade. If you choose to use the facade, be sure to uncomment the call to $app->withFacades()
in your bootstrap/app.php
file:
Queue::push(new ExampleJob);
Service Container
Features |
Laravel |
Lumen |
Basic |
 |
 |
Accessing The Container
The Laravel\Lumen\Application
instance is an extension of Illuminate\Container\Container
, so it may be treated as the service container for your application.
Resolving Instances
To resolve things out of the container, you may either type-hint the dependency you need on a class that is already automatically resolved by the container, such as a route Closure, controller constructor, controller method, middleware, event listener, or queued job. Or, you may use the app
function from anywhere in your application:
$instance = app(Something::class);
Testing
Features |
Laravel |
Lumen |
Basic |
 |
 |
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Wahyu Kristianto