Top Related Projects
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
A Laravel-Vue SPA starter kit.
The Laravel Boilerplate Project - https://laravel-boilerplate.com
Associate users with roles and permissions
Debugbar for Laravel (Integrates PHP Debug Bar)
Quick Overview
The gothinkster/laravel-realworld-example-app
is a real-world example application built using the Laravel framework. It implements a social blogging platform, similar to Medium, and serves as a reference for developers to learn and understand best practices in building a modern web application with Laravel.
Pros
- Comprehensive Example: The project provides a complete, production-ready application that covers a wide range of features and functionality, making it an excellent learning resource for Laravel developers.
- Best Practices: The codebase follows industry-standard best practices and design patterns, such as the use of repositories, services, and middleware, which can serve as a guide for developers.
- Testability: The application includes a comprehensive test suite, demonstrating the importance of testing in software development and providing a template for developers to follow.
- Documentation: The project's documentation is well-written and covers various aspects of the application, including setup, architecture, and deployment, making it easy for developers to get started.
Cons
- Complexity: The project may be overwhelming for beginners, as it covers a wide range of features and concepts that may be challenging to grasp for those new to Laravel or web development in general.
- Opinionated: The project follows a specific set of design decisions and architectural patterns, which may not align with the preferences or requirements of all developers.
- Outdated Dependencies: The project's dependencies may become outdated over time, requiring developers to manually update them to ensure the application remains secure and up-to-date.
- Limited Customization: The project is designed as a reference application, which may limit the ability of developers to customize it to fit their specific needs.
Getting Started
To get started with the gothinkster/laravel-realworld-example-app
, follow these steps:
- Clone the repository:
git clone https://github.com/gothinkster/laravel-realworld-example-app.git
- Navigate to the project directory:
cd laravel-realworld-example-app
- Install the dependencies:
composer install
- Create a new
.env
file and configure the necessary environment variables, such as the database connection details. - Generate an application key:
php artisan key:generate
- Run the database migrations:
php artisan migrate
- Start the development server:
php artisan serve
- Open your web browser and navigate to
http://localhost:8000
to view the application.
Competitor Comparisons
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
Pros of Laravel
- Provides a clean, minimal starting point for new Laravel projects
- Regularly updated with the latest Laravel framework version
- Includes essential configuration files and directory structure
Cons of Laravel
- Lacks real-world application examples and best practices
- Requires additional setup and configuration for complex features
- Does not include pre-built authentication or API functionality
Code Comparison
Laravel:
Route::get('/', function () {
return view('welcome');
});
Laravel Realworld Example App:
Route::get('api/articles/{slug}/comments', 'Api\CommentController@index');
Route::post('api/articles/{slug}/comments', 'Api\CommentController@store');
Route::delete('api/articles/{slug}/comments/{id}', 'Api\CommentController@destroy');
The Laravel repository provides a basic routing example, while the Laravel Realworld Example App demonstrates more complex API routing with resource-specific controllers.
Laravel offers a blank canvas for developers to build upon, making it ideal for custom projects. The Laravel Realworld Example App, on the other hand, provides a fully-functional application with real-world patterns and practices, making it an excellent learning resource and starting point for similar projects.
A Laravel-Vue SPA starter kit.
Pros of laravel-vue-spa
- More comprehensive Vue.js integration, including Vuex for state management
- Includes authentication features like social login and two-factor authentication
- Offers a more modern frontend setup with Vue Router and Single Page Application (SPA) architecture
Cons of laravel-vue-spa
- Less focused on adhering to a specific API specification (unlike laravel-realworld-example-app which follows RealWorld guidelines)
- May have a steeper learning curve due to its more complex frontend architecture
- Potentially less suitable for developers looking for a simpler, more backend-focused Laravel example
Code Comparison
laravel-vue-spa (Vue component):
<template>
<div class="container">
<router-view></router-view>
</div>
</template>
<script>
export default {
// Component logic
}
</script>
laravel-realworld-example-app (Blade template):
@extends('layouts.app')
@section('content')
<div class="container">
<!-- Page content -->
</div>
@endsection
The code snippets highlight the difference in frontend approaches. laravel-vue-spa uses Vue components and router, while laravel-realworld-example-app relies on traditional Blade templates for rendering.
The Laravel Boilerplate Project - https://laravel-boilerplate.com
Pros of Laravel Boilerplate
- More comprehensive feature set, including user management, role-based access control, and social authentication
- Includes a pre-built admin panel with Bootstrap 4 and CoreUI
- Offers multi-language support out of the box
Cons of Laravel Boilerplate
- Potentially more complex and harder to customize due to its extensive features
- May include unnecessary components for simpler projects
- Less focused on API development compared to Laravel RealWorld Example App
Code Comparison
Laravel Boilerplate (routes/backend/admin.php):
Route::get('dashboard', 'DashboardController@index')->name('dashboard');
Route::get('/', 'DashboardController@index')->name('home');
Laravel RealWorld Example App (routes/api.php):
Route::post('users/login', 'Auth\LoginController@login');
Route::post('users', 'Auth\RegisterController@register');
The code snippets show that Laravel Boilerplate focuses on backend routes and admin functionality, while Laravel RealWorld Example App emphasizes API endpoints for user authentication.
Both projects serve different purposes: Laravel Boilerplate provides a feature-rich starting point for full-stack applications, while Laravel RealWorld Example App is tailored for building RESTful APIs following the RealWorld specification.
Associate users with roles and permissions
Pros of laravel-permission
- Focused specifically on role-based permissions, providing a robust and flexible system
- Well-documented with extensive examples and use cases
- Actively maintained with frequent updates and a large community
Cons of laravel-permission
- Limited to permission management, not a full application example
- May require additional setup and integration with existing Laravel projects
- Potential performance impact for large-scale applications with complex permission structures
Code Comparison
laravel-permission:
$user->givePermissionTo('edit articles');
$user->assignRole('writer');
$user->hasPermissionTo('edit articles');
laravel-realworld-example-app:
$user->can('update', $article);
Gate::allows('update-article', $article);
$this->authorize('update', $article);
The laravel-permission package provides a more expressive and granular approach to managing permissions, while laravel-realworld-example-app uses Laravel's built-in authorization features. The former offers more flexibility in defining and assigning permissions, while the latter integrates seamlessly with Laravel's existing authorization system.
Debugbar for Laravel (Integrates PHP Debug Bar)
Pros of Laravel Debugbar
- Provides comprehensive debugging information for Laravel applications
- Easy to install and integrate into existing Laravel projects
- Offers real-time performance monitoring and query analysis
Cons of Laravel Debugbar
- Focused solely on debugging and development, not a full application example
- May impact performance when enabled in production environments
- Requires manual configuration for optimal use in complex applications
Code Comparison
Laravel Debugbar:
use Barryvdh\Debugbar\Facade as Debugbar;
Debugbar::info($object);
Debugbar::error('Error!');
Debugbar::warning('Watch out…');
Debugbar::addMessage('Another message', 'mylabel');
Laravel Realworld Example App:
public function index()
{
return $this->articles->getFeed(
Auth::user(),
$this->request->input('limit', 20),
$this->request->input('offset', 0)
);
}
Laravel Debugbar is a powerful debugging tool that enhances development workflow, while Laravel Realworld Example App serves as a comprehensive example of a real-world Laravel application. The former focuses on providing detailed debugging information, while the latter demonstrates best practices for building a full-featured Laravel application. Laravel Debugbar is more suitable for development and troubleshooting, whereas Laravel Realworld Example App serves as a learning resource and reference for Laravel application architecture.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Example Laravel codebase containing real world examples (CRUD, auth, advanced patterns and more) that adheres to the RealWorld spec and API.
This repo is functionality complete â PRs and issues welcome!
Getting started
Installation
Please check the official laravel installation guide for server requirements before you start. Official Documentation
Alternative installation is possible without local dependencies relying on Docker.
Clone the repository
git clone git@github.com:gothinkster/laravel-realworld-example-app.git
Switch to the repo folder
cd laravel-realworld-example-app
Install all the dependencies using composer
composer install
Copy the example env file and make the required configuration changes in the .env file
cp .env.example .env
Generate a new application key
php artisan key:generate
Generate a new JWT authentication secret key
php artisan jwt:generate
Run the database migrations (Set the database connection in .env before migrating)
php artisan migrate
Start the local development server
php artisan serve
You can now access the server at http://localhost:8000
TL;DR command list
git clone git@github.com:gothinkster/laravel-realworld-example-app.git
cd laravel-realworld-example-app
composer install
cp .env.example .env
php artisan key:generate
php artisan jwt:generate
Make sure you set the correct database connection information before running the migrations Environment variables
php artisan migrate
php artisan serve
Database seeding
Populate the database with seed data with relationships which includes users, articles, comments, tags, favorites and follows. This can help you to quickly start testing the api or couple a frontend and start using it with ready content.
Open the DummyDataSeeder and set the property values as per your requirement
database/seeds/DummyDataSeeder.php
Run the database seeder and you're done
php artisan db:seed
Note : It's recommended to have a clean database before seeding. You can refresh your migrations at any point to clean the database by running the following command
php artisan migrate:refresh
Docker
To install with Docker, run following commands:
git clone git@github.com:gothinkster/laravel-realworld-example-app.git
cd laravel-realworld-example-app
cp .env.example.docker .env
docker run -v $(pwd):/app composer install
cd ./docker
docker-compose up -d
docker-compose exec php php artisan key:generate
docker-compose exec php php artisan jwt:generate
docker-compose exec php php artisan migrate
docker-compose exec php php artisan db:seed
docker-compose exec php php artisan serve --host=0.0.0.0
The api can be accessed at http://localhost:8000/api.
API Specification
This application adheres to the api specifications set by the Thinkster team. This helps mix and match any backend with any other frontend without conflicts.
More information regarding the project can be found here https://github.com/gothinkster/realworld
Code overview
Dependencies
- jwt-auth - For authentication using JSON Web Tokens
- laravel-cors - For handling Cross-Origin Resource Sharing (CORS)
Folders
app
- Contains all the Eloquent modelsapp/Http/Controllers/Api
- Contains all the api controllersapp/Http/Middleware
- Contains the JWT auth middlewareapp/Http/Requests/Api
- Contains all the api form requestsapp/RealWorld/Favorite
- Contains the files implementing the favorite featureapp/RealWorld/Filters
- Contains the query filters used for filtering api requestsapp/RealWorld/Follow
- Contains the files implementing the follow featureapp/RealWorld/Paginate
- Contains the pagination class used to paginate the resultapp/RealWorld/Slug
- Contains the files implementing slugs to articlesapp/RealWorld/Transformers
- Contains all the data transformersconfig
- Contains all the application configuration filesdatabase/factories
- Contains the model factory for all the modelsdatabase/migrations
- Contains all the database migrationsdatabase/seeds
- Contains the database seederroutes
- Contains all the api routes defined in api.php filetests
- Contains all the application teststests/Feature/Api
- Contains all the api tests
Environment variables
.env
- Environment variables can be set in this file
Note : You can quickly set the database information and other variables in this file and have the application fully working.
Testing API
Run the laravel development server
php artisan serve
The api can now be accessed at
http://localhost:8000/api
Request headers
Required | Key | Value |
---|---|---|
Yes | Content-Type | application/json |
Yes | X-Requested-With | XMLHttpRequest |
Optional | Authorization | Token {JWT} |
Refer the api specification for more info.
Authentication
This applications uses JSON Web Token (JWT) to handle authentication. The token is passed with each request using the Authorization
header with Token
scheme. The JWT authentication middleware handles the validation and authentication of the token. Please check the following sources to learn more about JWT.
Cross-Origin Resource Sharing (CORS)
This applications has CORS enabled by default on all API endpoints. The default configuration allows requests from http://localhost:3000
and http://localhost:4200
to help speed up your frontend testing. The CORS allowed origins can be changed by setting them in the config file. Please check the following sources to learn more about CORS.
Top Related Projects
Laravel is a web application framework with expressive, elegant syntax. We’ve already laid the foundation for your next big idea — freeing you to create without sweating the small things.
A Laravel-Vue SPA starter kit.
The Laravel Boilerplate Project - https://laravel-boilerplate.com
Associate users with roles and permissions
Debugbar for Laravel (Integrates PHP Debug Bar)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot