建構與交付
透過 專為提升生產力
而打造的工具來開發軟體

Laravel 為網路工匠提供完整的生態系統。我們的開源 PHP 框架、產品、套件和入門套件,為您提供建構、部署和監控網路應用程式所需的一切。

觀看影片 2 分鐘

受到全球數千家企業信賴

生態系統

一個具有健全生態系統的 PHP 框架

Laravel 開箱即用,為所有現代網路應用程式所需的常見功能提供優雅的解決方案。我們的第一方套件為特定問題提供明確的解決方案,讓您無需重新發明輪子。

後端

不言自明的程式碼

簡單優雅的語法,驅動驚人的功能。每個功能都經過深思熟慮,旨在創造周到且具凝聚力的開發體驗。

驗證

1將驗證中介軟體新增至您的 Laravel 路由

                                                    
1Route::get('/profile', ProfileController::class)
2 ->middleware('auth');

2您可以透過 Auth facade 存取已驗證的使用者

                                                    
1use Illuminate\Support\Facades\Auth;
2 
3$user = Auth::user();

閱讀驗證文件

授權

1為您的模型定義政策

                                                    
1public function update(User $user, Post $post): Response
2{
3 return $user->id === $post->user_id
4 ? Response::allow()
5 : Response::deny('You do not own this post.');
6}

2透過 Gate facade 使用政策

                                                    
1Gate::authorize('update', $post);

閱讀授權文件

Eloquent

1為您的資料庫表格定義模型

                                                    
1<?php
2 
3namespace App\Models;
4 
5use Illuminate\Database\Eloquent\Model;
6 
7class Flight extends Model
8{
9 // ...
10}

2使用 Eloquent 從資料庫擷取記錄

                                                    
1use App\Models\Flight;
2 
3foreach (Flight::all() as $flight) {
4 echo $flight->name;
5}

閱讀 Eloquent 文件

遷移

1為您的資料庫表格建立遷移

                                                    
1php artisan make:migration create_posts_table --create=posts

2在您的遷移檔案中定義結構描述

                                                    
1class CreatePostsTable extends Migration
2{
3 public function up()
4 {
5 Schema::create('posts', function (Blueprint $table) {
6 $table->id();
7 $table->string('title');
8 $table->text('content');
9 $table->foreignId('user_id')->constrained()->onDelete('cascade');
10 $table->timestamps();
11 });
12 }
13}

閱讀遷移文件

驗證

1在您的控制器中定義驗證規則

                                                    
1public function store(Request $request)
2{
3 $validated = $request->validate([
4 'title' => 'required|max:255',
5 'content' => 'required',
6 'email' => 'required|email',
7 ]);
8}

2在您的視圖中處理驗證錯誤

                                                    
1@if ($errors->any())
2 <div class="alert alert-danger">
3 <ul>
4 @foreach ($errors->all() as $error)
5 <li>{{ $error }}</li>
6 @endforeach
7 </ul>
8 </div>
9@endif

閱讀驗證文件

通知與郵件

1定義通知內容

                                                    
1class PostCreated extends Notification
2{
3 public function via()
4 {
5 return ['mail', 'database']; // Send via mail and store in database
6 }
7 
8 public function toMail($notifiable)
9 {
10 return (new MailMessage)
11 ->subject('New Post Created')
12 ->line('A new post has been created: ' . $this->post->title)
13 ->action('View Post', url('/posts/' . $this->post->id))
14 ->line('Thank you for using our application!');
15 }
16}

2將通知傳送給使用者

                                                    
1public function store(Request $request)
2{
3 $post = Post::create($request->all());
4 
5 $request->user()->notify(new PostCreated($post));
6}

閱讀通知與郵件文件

檔案儲存

1設定您的檔案系統

                                                    
1FILESYSTEM_DRIVER=s3

2在您的控制器中處理檔案上傳

                                                    
1public function store(Request $request)
2{
3 if ($request->hasFile('image')) {
4 $path = $request->file('image')->store('images', 'public');
5 }
6}

閱讀檔案儲存文件

工作佇列

1定義工作邏輯

                                                    
1class ProcessPost implements ShouldQueue
2{
3 public function handle()
4 {
5 $this->post->update([
6 'rendered_content' => Str::markdown($this->post->content)
7 ]);
8 }
9}

2從您的控制器分派工作

                                                    
1public function store(Request $request)
2{
3 $post = Post::create($request->all());
4 
5 ProcessPost::dispatch($post);
6}

閱讀佇列文件

任務排程

1定義命令邏輯

                                                    
1class SendEmails extends Command
2{
3 protected $signature = 'emails:send';
4 
5 protected $description = 'Send scheduled emails';
6 
7 public function handle()
8 {
9 // Send your emails...
10 }
11}

2排程任務

                                                    
1Schedule::command('emails:send')->daily();

閱讀任務排程文件

測試

1使用 Pest 撰寫您的測試

                                                    
1it('can create a post', function () {
2 $response = $this->post('/posts', [
3 'title' => 'Test Post',
4 'content' => 'This is a test post content.',
5 ]);
6 
7 $response->assertStatus(302);
8 
9 $this->assertDatabaseHas('posts', [
10 'title' => 'Test Post',
11 ]);
12});

2在命令列上執行測試

                                                    
1php artisan test

閱讀測試文件

事件與 WebSockets

1建立您的事件

                                                    
1class PostCreated implements ShouldBroadcast
2{
3 use Dispatchable, SerializesModels;
4 
5 public $post;
6 
7 public function __construct(Post $post)
8 {
9 $this->post = $post;
10 }
11}

2在您的控制器中分派事件

                                                    
1public function store(Request $request)
2{
3 $post = Post::create($request->all());
4 
5 PostCreated::dispatch($post);
6}

3在您的 JavaScript 檔案中,監聽事件

                                                    
1Echo.channel("posts." + postId).listen("PostCreated", (e) => {
2 console.log("Post created:", e.post);
3});

閱讀事件文件

前端

適用於任何堆疊的前端

無論您偏好傳統的 PHP 後端、使用 Laravel Livewire 的現代前端,或對 React 和 Vue 百用不厭,Laravel 都能讓您在極短的時間內交付高度精美且可維護的應用程式。

                                                    
1class UserController
2{
3 public function index()
4 {
5 $users = User::active()
6 ->orderByName()
7 ->get(['id', 'name', 'email']);
8 
9 return Inertia::render('Users', [
10 'users' => $users,
11 ]);
12 }
13}

Inertia

現代巨石

Laravel Inertia 為您的 Laravel 體驗增強功能,並與 React、Vue 和 Svelte 無縫協作。Inertia 處理您後端和前端之間的路由和資料傳輸,無需建置 API 或維護兩組路由。

閱讀 Inertia 文件

                                                    
1class Counter extends Component
2{
3 public $count = 1;
4 
5 public function increment()
6 {
7 $this->count++;
8 }
9 
10 public function decrement()
11 {
12 $this->count--;
13 }
14 
15 public function render()
16 {
17 return view('livewire.counter');
18 }
19}

Livewire

超強大的 Blade

Laravel Livewire 透過將動態、反應式介面直接帶入您的 Blade 範本,轉型您的 Laravel 應用程式。Livewire 無縫橋接伺服器端渲染和用戶端互動之間的差距,讓您無需離開 Laravel 的舒適環境,即可建立現代化、互動式元件。

閱讀 Livewire 文件

                                                    
1Route::get('/api/user', function (Request $request) {
2 return $request->user();
3})->middleware('auth:sanctum');

SPA 和行動應用程式

內建驗證

Laravel 使開發人員能夠輕鬆高效地為單頁應用程式 (SPA) 和行動應用程式建置穩健的後端。憑藉對 RESTful API、驗證和資料庫管理的內建支援,Laravel 簡化了將您的後端連接到 Vue.js 或 React 等現代前端框架的流程。

閱讀 Sanctum 文件

部署

託管或自行託管的部署平台

Laravel Cloud 為 Laravel 應用程式提供完全託管的應用程式平台,而 Forge 則允許您自行管理執行 Laravel 應用程式的 VPS 伺服器。

Cloud

雲端

產品

為只想交付下一個偉大創意的開發人員和團隊建置的完全託管應用程式平台。

方案起價每月 $0.00

Forge

Forge

產品

在 DigitalOcean、Akamai、Vultr、Amazon、Hetzner 等平台上佈建 VPS 伺服器並部署無限的 PHP 應用程式。

方案起價每月 $12.00

監控

應用程式監控,日誌記錄和測試

每個 Laravel 應用程式都可以透過監控、可觀察性和測試工具實現企業級品質,讓您充滿信心地交付產品。

Nightwatch

Nightwatch

產品

為需要確切了解其應用程式中發生情況的 Laravel 開發人員和團隊建置的監控工具。

價格即將推出

Pulse

脈衝

套件

一目瞭然地深入了解您應用程式的效能和使用情況。追蹤慢速工作和端點等瓶頸,找出最活躍的使用者等等。

免費

Telescope

望遠鏡

套件

優雅的偵錯助理,可深入了解進入您應用程式的要求、例外、日誌項目、資料庫查詢、佇列工作等等。

免費

Pest

Pest

套件

Pest 是一個測試框架,專注於簡潔性,經過精心設計,旨在帶回 PHP 測試的樂趣。

免費

社群

深受開發人員、新創公司和企業信賴

加入全球成千上萬的開發人員和公司的行列。

「我使用 Laravel 將近十年了,從未想過要改用其他任何東西。」
Adam Wathan Tailwind 創辦人
Adam Wathan
「Laravel 是我們用於大大小小網路專案的酵母和多功能工具。歷經 10 年,它仍然新鮮且實用。」
Ian Callahan 哈佛藝術博物館
Ian Callahan
「Laravel 消除了建置現代化、可擴展網路應用程式的痛苦。」
Aaron Francis Try Hard Studios 共同創辦人
Aaron Francis
「Laravel 成長為一個令人驚嘆且活躍的社群。Laravel 不僅僅是一個 PHP 框架。」
Bobby Bouwmann Enrise 開發人員
Bobby Bouwmann
「Laravel 是 PHP 生態系統中的一股清流,周圍環繞著一個出色的社群。」
Erika Heidi Minicli 創作者
Erika Heidi
「框架、生態系統和社群 - 它是完美的套件。」
Zuzana Kunckova Larabelles 創辦人
Zuzana Kunckova
「使用 Laravel 交付應用程式意味著在效能、彈性和簡潔性之間取得平衡,同時確保出色的開發人員體驗。」
Peter Steenbergen Elastic
Peter Steenbergen
「AI 開發進展迅速。有了 Laravel,交付 AI 驅動的應用程式從未如此簡單。」
Jordan Price Bestie AI
Jordan Price
「有了 Laravel,我們可以在幾個月內為客戶建置可擴展、高效能的網路應用程式和 API,否則這需要數年時間。」
Matt Stauffer Tighten
Matt Stauffer
「Laravel 一流的測試工具讓我安心地快速交付穩健的應用程式。」
Michael Dyrynda Laravel Artisan + Laracon AU 組織者
Michael Dyrynda
「Laravel 讓建立每天處理數億個請求和數十億個背景作業的服務變得非常簡單。」
Sebastien Armand Square 開發人員
Sebastien Armand
「Laravel 幫助我比任何其他解決方案更快地推出產品,讓我能夠隨著社群的發展更快地進入市場。」
Steve McDougall Laravel Transporter 創作者
Steve McDougall
「Laravel 就像我職業生涯和事業的火箭燃料。」
Chris Arter Bankrate 開發人員
Chris Arter
「在過去十年中,我一直將 Laravel 用於每個專案,至今為止,沒有任何東西能與之相比。」
Philo Hermans Anystack 創辦人
Philo Hermans
「我使用 Laravel 已超過 10 年,我無法想像沒有它如何使用 PHP。」
Eric L. Barnes Laravel News 創辦人
Eric L. Barnes
「Laravel 適用於那些因為能夠編寫程式碼而不是因為必須編寫程式碼而編寫程式碼的開發人員。」
Luke Downing 創客 + 開發人員
Luke Downing
「Laravel 生態系統是我們業務成功的關鍵。該框架使我們能夠快速行動並定期交付產品。」
Jack Ellis Fathom Analytics 創辦人
Jack Ellis
「多年來,我一直很欣賞 Laravel 專注於將 DX 推向新的高度。它設計精良,並且擁有出色的文件。」
Freek Van der Herten Spatie 所有者
Freek Van der Herten
「Laravel 簡直是一種樂趣。它讓我能夠以創紀錄的速度愉快地建置任何我想要的網路相關事物。」
Caleb Porzio Livewire 和 Alpine.js 創作者
Caleb Porzio
「直到我嘗試了(許多)不同的生態系統,我才完全體會到 Laravel 的一站式解決方案。Laravel 自成一格!」
Joseph Silber Bouncer 創作者
Joseph Silber

準備好創造您的下一個偉大創意了嗎?

立即開始並交付令人驚豔的作品。

Laravel 是最具生產力的方式,可以
建置、部署和監控軟體。