跳转到内容

与 Laravel 对比

Goravel 深受 Laravel 框架启发,旨在为 Go 开发者带来类似的优雅和简洁性。 以下是 Goravel 与 Laravel 之间的一些关键对比,以帮助你了解 Goravel 如何与 Laravel 的功能保持一致:

功能GoravelLaravel代码示例
Artisan 命令行./artisan key:generate
php artisan key:generate
用户认证facades.Auth(ctx).Login(&user)
Auth::login($user)
用户授权facades.Gate().Allows("update", user)
Gate::allows('update', $user)
缓存facades.Cache().Put("key", "value", time.Minute)
Cache::put('key', 'value', 60)
Carboncarbon.Now().AddDays(1)
Carbon::now()->addDays(1)
自定义配置facades.Config().GetString("app.name")
config('app.name')
Cryptfacades.Crypt().EncryptString("text")
Crypt::encryptString('text')
数据库facades.DB().Table("users").Get(&users)
DB::table('users')->get()
事件系统facades.Event().Job(&events.Order{}).Dispatch()
Order::dispatch()
数据工厂facades.Orm().Factory().Make(&user)
User::factory()->make()
文件存储facades.Storage().Put("file.txt", "content")
Storage::put('file.txt', 'content')
Hashfacades.Hash().Make("password")
Hash::make('password')
HTTPfacades.Route().Get("/", controller.Index)
Route::get('/', [Controller::class, 'index'])
HTTP 客户端facades.Http().Get("https://api.com")
Http::get('https://api.com')
本地化facades.Lang(ctx).Get("messages.welcome")
__('messages.welcome')
日志facades.Log().Info("message")
Log::info('message')
邮件facades.Mail().To("user@example.com").Send()
Mail::to('user@example.com')->send(new Order())
Mock
数据库迁移./artisan migrate
php artisan migrate
ORMfacades.Orm().Query().Find(&user, 1)
User::find(1)
扩展包开发
进程facades.Process().Run("ls", "-la")
`Process::run('ls -la')
队列facades.Queue().Job(&jobs.Process{}).Dispatch()
Process::dispatch()
速率限制facades.RateLimiter().For("global", ...)
RateLimiter::for('global', ...)
数据填充facades.Seeder().Call([]seeder.Seeder{&User{}})
$this->call([User::class])
Sessionctx.Request().Session().Put("key", "value")
session(['key' => 'value'])
任务调度facades.Schedule().Command("emails:send").Daily()
Schedule::command('emails:send')->daily()
测试
表单验证ctx.Request().ValidateRequest()
$request->validate()
视图ctx.Response().View().Make("welcome.tmpl")
view('welcome')
Grpc🚧
通知🚧
广播🚧
Livewire🚧

基于 MIT 许可发布