按 RealWorld 规范实现后端 API,可与任意符合该规范的前端搭配使用
laravel-realworld-example-app — Laravel 启动器模板
作者 MiguelMoutela
基于 Laravel 的 RealWorld 后端 API 启动器,实现 CRUD、JWT 认证与文章、评论、标签、关注等接口。
看看你的网站会是什么样
浏览真实页面截图,比较内容排版与手机效果。点击下方缩略图切换,放大查看整页细节。
全部页面与视图 3
截图用于了解视觉与布局,交互效果请以实际项目为准。
值得关注的模板亮点
从已有项目资料中,快速了解它的特点。
使用 JWT 处理认证,令牌通过 Authorization 请求头以 Token 方案传递
默认对所有 API 端点启用 CORS,允许 localhost:3000 与 localhost:4200 来源
提供 DummyDataSeeder,可生成包含用户、文章、评论、标签、收藏和关注关系的种子数据
代码按过滤器、控制器、中间件、表单请求、分页器、转换器分层组织
模板详细介绍
这是一个 Laravel 后端 API 启动器,按照 RealWorld 规范与 API 实现示例代码库,覆盖 CRUD、认证以及更复杂的业务模式。仓库说明中标注功能完整,并欢迎提交 PR 和 issue。
项目使用 JWT 处理认证,令牌通过 Authorization 请求头以 Token 方案传递,由 JWT 认证中间件完成校验;默认对所有 API 端点启用 CORS,允许来自 localhost:3000 与 localhost:4200 的请求,便于前端联调。依赖方面包括 eloquent-sluggable(自动生成唯一 slug)、jwt-auth(JWT 认证)与 laravel-cors(跨域资源共享)。
代码结构上,app 目录存放 Eloquent 模型,app/Filters 存放用于过滤 API 请求的查询过滤器,app/Http/Controllers/Api 存放 API 控制器,app/Http/Middleware 存放 JWT 认证中间件,app/Http/Requests/Api 存放 API 表单请求,app/Paginate 存放自定义分页器,app/Transformers 存放数据转换器;database 下包含模型工厂、迁移与种子文件,路由集中在 routes/api.php。
需要注意:仓库已迁移至 gothinkster/laravel-realworld-example-app,当前仓库为旧地址;README 中的克隆命令指向 SandeeshS/laravel-realworld-example-app,与仓库归属不一致。资料未说明框架版本、运行环境要求或生产部署方式,使用前应自行核对依赖清单与兼容性。
适合你的项目吗?
适用场景
- 为 RealWorld 规范的前端项目提供配套后端 API
- 学习 Laravel 中 JWT 认证与 API 中间件的实现方式
- 通过种子数据快速搭建带关联内容的接口测试环境
- 参考查询过滤器、数据转换器与自定义分页器的组织方式
适合人群
- 需要 RealWorld 规范后端实现的开发者
- 希望研究 Laravel API 分层结构的学习者
- 准备为符合 RealWorld 规范的前端联调接口的团队
上手与定制指南
结合仓库当前版本的说明,按下面的资料检查内容、配置与运行要求。
- 1
仓库已迁移至 gothinkster/laravel-realworld-example-app,README 中的克隆地址与实际仓库不一致,克隆前需确认目标地址
- 2
安装依赖使用 composer install,随后复制 .env.example 为 .env 并配置数据库连接
- 3
依次执行 php artisan key:generate 与 php artisan jwt:generate 生成应用密钥和 JWT 密钥
- 4
运行 php artisan migrate 前必须先在 .env 中设置正确的数据库连接信息
- 5
可选执行 php artisan db:seed 填充种子数据,建议在干净数据库上执行,可用 php artisan migrate:refresh 重置
授权与来源资料
使用条件与限制
免费使用 · 保留许可声明本次收录的是公开仓库中采用 MIT 许可的免费版本;免费范围为该版本代码,不代表外部服务或第三方素材免费。
使用时需要遵守
- 允许免费使用、修改、商用和分发该版本代码。
- 分发代码副本或实质性部分时,保留原作者版权声明和完整 MIT 许可声明。
- 代码按现状提供;担保与责任限制以原许可证及适用法律为准。
额外费用与待核对事项
- 演示图片、字体、图标及其他第三方素材需按各自许可核对,不能仅凭代码的 MIT 许可判断。
- 域名、托管、数据库、支付或 AI 等外部服务可能另外收费。
- 该仓库已迁移至 gothinkster/laravel-realworld-example-app,当前地址为旧仓库,后续维护与更新可能不再在此进行,使用前应确认目标仓库。
- 运行数据库迁移前必须先在 .env 中设置正确的数据库连接信息,否则迁移无法正常执行。
- 种子数据用于快速测试 API 或与前端联调,需先打开 DummyDataSeeder 按需设置属性值,再执行 php artisan db:seed。
- 建议在干净数据库上执行种子填充,可用 php artisan migrate:refresh 重置数据库,该操作会清空现有数据。
- 默认 CORS 仅允许来自 localhost:3000 与 localhost:4200 的请求,用于前端联调;如需其他来源,必须在配置文件中修改允许的来源。
- 认证依赖 JWT,令牌需通过 Authorization 请求头以 Token 方案传递,客户端必须按此格式携带令牌才能访问受保护接口。
查看原文依据
Permission is hereby granted, free of charge
许可证原文
This repo has been moved to [gothinkster/laravel-realworld-example-app](https://github.com/gothinkster/laravel-realworld-example-app)
README 原文
**Make sure you set the correct database connection information before running the migrations**
README 原文
**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.**
README 原文
***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
README 原文
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.
README 原文
https://github.com/MiguelMoutela/laravel-realworld-example-app/blob/master/LICENSEhttps://github.com/MiguelMoutela/laravel-realworld-example-app/blob/master/readme.mdThis applications uses JSON Web Token (JWT) to handle authentication. The token is passed with each request using the `Authorization` header with `Token` scheme.
README 原文
DeepSeek 根据仓库许可证和 README 整理 ·2026-10-12。结果仅覆盖已读取资料,依赖、图片、字体及后续条款变更以各自原文为准。
项目核对记录与介绍依据
模板资料
- 来源平台
- GitHub
- 资料与维护参考分
- 资料一般 · 65 / 100
- 技术栈
- Laravel
- 网站类型
- 启动器
这个分数如何计算
本站按许可资料(最高30分)、演示链接(12分)、预览图(10分)、Star数(15分)、记录的维护时间(15分)、描述完整度(8分)、功能记录(5分)和分类资料(5分)计算。它不是代码、安全或性能测试,也不是 Google 评分;有链接不代表已实测可用。
这个项目需要核对什么
- 记录的仓库更新时间
- 2017-05-03
- 截图检查日期
- 2026-10-12
已收录演示链接。请用你的内容与屏幕尺寸检查;有演示不代表表单、认证或支付已经可用。
目录记录的主要技术栈是 Laravel。请通过依赖清单和锁文件核对实际版本与托管要求。这些说明基于收录资料,不代表代码审计或部署实测。
查看具体选型方法 →介绍的制作与核对状态
介绍由 AI 辅助整理目录与仓库资料。仓库作者不等于这篇介绍的审核者。
审核声明: [email protected] · 2026-10-13
查看当时使用的来源资料
SHA-256: 869cc8dea45de64a86e5ebe13c3d51239738ede6bce2a5d324021549c255658d
2026-10-12T22:14:18.032Z
来源文件 / 仓库## This repo has been moved to [gothinkster/laravel-realworld-example-app](https://github.com/gothinkster/laravel-realworld-example-app)
# 
> ### Example Laravel codebase containing real world examples (CRUD, auth, advanced patterns and more) that adheres to the [RealWorld](https://github.com/gothinkster/realworld-example-apps) spec and API.
This repo is functionality complete — PR's and issues welcome!
----------
# Getting started
## Installation
Clone the repository
git clone [email protected]:SandeeshS/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 [email protected]:SandeeshS/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](#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
## API Specification
This application adheres to the api specifications set by the [Thinkster](https://github.com/gothinkster) team. This helps mix and match any backend with any other frontend without conflicts.
> [Full API Spec](https://github.com/gothinkster/realworld/tree/master/api)
More information regarding the project can be found here https://github.com/gothinkster/realworld
----------
# Code overview
## Dependencies
- [eloquent-sluggable](https://github.com/cviebrock/eloquent-sluggable) - For auto generation of unique slugs
- [jwt-auth](https://github.com/tymondesigns/jwt-auth) - For authentication using JSON Web Tokens
- [laravel-cors](https://github.com/barryvdh/laravel-cors) - For handling Cross-Origin Resource Sharing (CORS)
## Folders
- `app` - Contains all the Eloquent models
- `app/config` - Contains all the application configuration files
- `app/Filters` - Contains the query filters used for filtering api requests
- `app/Http/Controllers/Api` - Contains all the api controllers
- `app/Http/Middleware` - Contains the JWT auth middleware
- `app/Http/Requests/Api` - Contains all the api form requests
- `app/Paginate` - Contains the custom pagintor used to paginate the result
- `app/Transformers` - Contains all the data transformers
- `database/factories` - Contains the model factory for all the models
- `database/migrations` - Contains all the database migrations
- `database/seeds` - Contains the database seeder
- `routes` - Contains all the api routes defined in api.php file
## 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](#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.
- https://jwt.io/introduction/
- https://self-issued.info/docs/draft-ietf-oauth-json-web-token.html
----------
# 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.
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
- https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
- https://www.w3.org/TR/cors
看看同类模板
对比同技术栈与用途的模板,找到更适合的视觉与内容结构。

sage
WordPress starter theme with Laravel Blade components and templates, Tailwind CSS, and block editor support
Laravel · 启动器

wave
Wave - The Software as a Service Starter Kit, designed to help you build the SAAS of your dreams 🚀 💰
Laravel · SaaS

filament-starter
A beautiful starting point for your next TALL stack project using Filament. ⚡
Laravel · 启动器

electrik
Laravel SaaS starter kit: auth, teams, Stripe billing, and Slate 3 — Composer package for Laravel 12
Laravel · SaaS

php-saas
The everything-included starter kit for your next idea
Laravel · SaaS

filament-jetstream
A Laravel starter kit built with Filament inspired by Jetstream.
Laravel · 启动器
