Skip to content

Commit 2a6ad9e

Browse files
author
王赛
committed
Merge pull request #29 from mpandar/master
同步了部分英文文档
2 parents 48a59c2 + edd9892 commit 2a6ad9e

28 files changed

+511
-99
lines changed

billing.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
- [Resuming A Subscription](#resuming-a-subscription)
1111
- [Checking Subscription Status](#checking-subscription-status)
1212
- [Handling Failed Payments](#handling-failed-payments)
13+
- [Handling Other Stripe Webhooks](#handling-other-stripe-webhooks)
1314
- [Invoices](#invoices)
1415

1516
<a name="introduction"></a>
1617
## Introduction
1718

18-
Laravel Cashier provides an expressive, fluent interface to [Stripe's](https://stripe.com) subscription billing services. It handles almost all of the boilerplate subscription billing code you are dreading writing. In addition to basic subscription management, Cashier can handle coupons, swapping subscription, subscription "quantites", cancellation grace periods, and even generate invoice PDFs.
19+
Laravel Cashier provides an expressive, fluent interface to [Stripe's](https://stripe.com) subscription billing services. It handles almost all of the boilerplate subscription billing code you are dreading writing. In addition to basic subscription management, Cashier can handle coupons, swapping subscription, subscription "quantities", cancellation grace periods, and even generate invoice PDFs.
1920

2021
<a name="configuration"></a>
2122
## Configuration
@@ -32,7 +33,7 @@ Next, register the `Laravel\Cashier\CashierServiceProvider` in your `app` config
3233

3334
#### Migration
3435

35-
Before using Cashier, we'll need to add several columns to your database. Don't worry, you can use the `cashier:table` Artisan command to create a migration to add the necessary column. Once the migration has been created, simply run the `migrate` command.
36+
Before using Cashier, we'll need to add several columns to your database. Don't worry, you can use the `cashier:table` Artisan command to create a migration to add the necessary column. For example, to add the column to the users table use `php artisan cashier:table users`. Once the migration has been created, simply run the `migrate` command.
3637

3738
#### Model Setup
3839

@@ -70,14 +71,24 @@ If you would like to apply a coupon when creating the subscription, you may use
7071
->withCoupon('code')
7172
->create($creditCardToken);
7273

73-
The `subscription` method will automatically create the Stripe subscription, as well as update your database with Stripe customer ID and other relevant billing information.
74+
The `subscription` method will automatically create the Stripe subscription, as well as update your database with Stripe customer ID and other relevant billing information. If your plan has a trial configured in Stripe, the trial end date will also automatically be set on the user record.
7475

75-
If your plan has a trial period, make sure to set the trial end date on your model after subscribing:
76+
If your plan has a trial period that is **not** configured in Stripe, you must set the trial end date manually after subscribing:
7677

7778
$user->trial_ends_at = Carbon::now()->addDays(14);
7879

7980
$user->save();
8081

82+
### Specifying Additional User Details
83+
84+
If you would like to specify additional customer details, you may do so by passing them as second argument to the `create` method:
85+
86+
$user->subscription('monthly')->create($creditCardToken, [
87+
'email' => $email, 'description' => 'Our First Customer'
88+
]);
89+
90+
To learn more about the additional fields supported by Stripe, check out Stripe's [documentation on customer creation](https://stripe.com/docs/api#create_customer).
91+
8192
<a name="no-card-up-front"></a>
8293
## No Card Up Front
8394

@@ -110,12 +121,12 @@ Sometimes subscriptions are affected by "quantity". For example, your applicatio
110121
$user->subscription()->increment();
111122

112123
// Add five to the subscription's current quantity...
113-
$user->subscription()->increment(5)
124+
$user->subscription()->increment(5);
114125

115126
$user->subscription->decrement();
116127

117128
// Subtract five to the subscription's current quantity...
118-
$user->subscription()->decrement(5)
129+
$user->subscription()->decrement(5);
119130

120131
<a name="cancelling-a-subscription"></a>
121132
## Cancelling A Subscription
@@ -183,6 +194,13 @@ The `everSubscribed` method may be used to determine if the user has ever subscr
183194
//
184195
}
185196

197+
The `onPlan` method may be used to determine if the user is subscribed to a given plan based on its ID:
198+
199+
if ($user->onPlan('monthly'))
200+
{
201+
//
202+
}
203+
186204
<a name="handling-failed-payments"></a>
187205
## Handling Failed Payments
188206

@@ -192,16 +210,16 @@ What if a customer's credit card expires? No worries - Cashier includes a Webhoo
192210

193211
That's it! Failed payments will be captured and handled by the controller. The controller will cancel the customer's subscription after three failed payment attempts. The `stripe/webhook` URI in this example is just for example. You will need to configure the URI in your Stripe settings.
194212

195-
If you have additional Stripe webhook events you would like to handle, simply extend the Webhook controller:
213+
<a name="handling-other-stripe-webhooks"></a>
214+
## Handling Other Stripe Webhooks
215+
216+
If you have additional Stripe webhook events you would like to handle, simply extend the Webhook controller. Your method names should correspond to Cashier's expected convention, specifically, methods should be prefixed with `handle` and the name of the Stripe webhook you wish to handle. For example, if you wish to handle the `invoice.payment_succeeded` webhook, you should add a `handleInvoicePaymentSucceeded` method to the controller.
196217

197218
class WebhookController extends Laravel\Cashier\WebhookController {
198219

199-
public function handleWebhook()
220+
public function handleInvoicePaymentSucceeded($payload)
200221
{
201-
// Handle other events...
202-
203-
// Fallback to failed payment check...
204-
return parent::handleWebhook();
222+
// Handle The Event
205223
}
206224

207225
}

cn/facades.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Facades(一种设计模式,通常翻译为外观模式)提供了一个"sta
114114

115115
下面你会找到所有的facade以及其包含的类。这是一个非常有用的工具,可以根据给定的facade快速定位到API文档。适用于[IoC 绑定](/docs/ioc) 的也同时给出了其key。
116116

117+
117118
Facade | Class | IoC Binding
118119
------------- | ------------- | -------------
119120
App | [Illuminate\Foundation\Application](http://laravel.com/api/4.2/Illuminate/Foundation/Application.html) | `app`
@@ -154,10 +155,9 @@ SSH | [Illuminate\Remote\RemoteManager](http://laravel.com/api/4.2/Illuminate/
154155
SSH (Instance) | [Illuminate\Remote\Connection](http://laravel.com/api/4.2/Illuminate/Remote/Connection.html) |
155156
URL | [Illuminate\Routing\UrlGenerator](http://laravel.com/api/4.2/Illuminate/Routing/UrlGenerator.html) | `url`
156157
Validator | [Illuminate\Validation\Factory](http://laravel.com/api/4.2/Illuminate/Validation/Factory.html) | `validator`
157-
Validator (Instance) | [Illuminate\Validation\Validator](http://laravel.com/api/4.2/Illuminate/Validation/Validator.html)
158+
Validator (Instance) | [Illuminate\Validation\Validator](http://laravel.com/api/4.2/Illuminate/Validation/Validator.html) |
158159
View | [Illuminate\View\Factory](http://laravel.com/api/4.2/Illuminate/View/Factory.html) | `view`
159160
View (Instance) | [Illuminate\View\View](http://laravel.com/api/4.2/Illuminate/View/View.html) |
160161

161162

162-
163163
译者:mpandar(马胜盼)

cn/homestead.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Laravel Homestead是一个官方的、预封装的Vagrant“箱子”,它提
1515

1616
Homestead能运行在所有的Windows、Mac和Linux上,它包含了Nginx、PHP 5.5、MySQL、Postgres、Redis、Memcached和你开发神奇的Laravel应用程序需要的所有其它软件。
1717

18+
Homestead is currently built and tested using Vagrant 1.6.
19+
1820
<a name="included-software"></a>
1921
## 包含的软件
2022

@@ -108,7 +110,7 @@ Homestead能运行在所有的Windows、Mac和Linux上,它包含了Nginx、PHP
108110
109111
### 添加额外站点
110112

111-
一旦你的Homestead环境被分配并运行,你可能想为Laravel应用程序添加额外的Nginx站点。在一个Homestead环境中,你可以按意愿运行尽可能多的Laravel应用程序。有两种方法可以做到这一点。首先,你可以简单的添加站点到“Homestead.yaml”文件里,先对箱子执行“vagrant destroy”命令,然后再执行“vagrant up”命令。
113+
一旦你的Homestead环境被分配并运行,你可能想为Laravel应用程序添加额外的Nginx站点。在一个Homestead环境中,你可以按意愿运行尽可能多的Laravel应用程序。有两种方法可以做到这一点。首先,你可以简单的添加站点到“Homestead.yaml”文件里,先对箱子执行“vagrant destroy”命令,然后再执行“vagrant provision”命令。
112114

113115
或者,你可以使用Homestead环境里的“serve”脚本。想使用“serve”脚本,先SSH到Homestead环境并运行下面的命令:
114116

cn/installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Composer 安装完成后,下载[最新版Laravel框架](https://github.com/lar
3636

3737
Laravel 框架对系统环境有如下要求:
3838

39-
- PHP >= 5.3.7
39+
- PHP >= 5.4
4040
- MCrypt PHP 扩展
4141

4242
从 PHP 5.5 版本开始,针对某些操作系统的安装包需要你自己手工安装 PHP 的 JSON 扩展模块。如果你使用的是 Ubuntu,可以通过, `apt-get install php5-json` 命令直接安装。

cn/quick.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Laravel 快速入门
22

33
- [安装](#installation)
4+
- [本地开发环境](#local-development-environment)
45
- [路由](#routing)
56
- [创建视图](#creating-a-view)
67
- [创建迁移](#creating-a-migration)
78
- [Eloquent ORM](#eloquent-orm)
89
- [显示数据](#displaying-data)
10+
- [部署应用](#deploying-your-application)
911

1012
<a name="installation"></a>
1113
## 安装
@@ -42,6 +44,20 @@ Typically, you may use a web server such as Apache or Nginx to serve your Larave
4244

4345
After installing the framework, take a glance around the project to familiarize yourself with the directory structure. The `app` directory contains folders such as `views`, `controllers`, and `models`. Most of your application's code will reside somewhere in this directory. You may also wish to explore the `app/config` directory and the configuration options that are available to you.
4446

47+
<a name="local-development-environment"></a>
48+
## Local Development Environment
49+
50+
In the past, configuring a local PHP development environment on your machine was a headache. Installing the proper version of PHP, required extensions, and other needed components is time consuming and confusing. Instead, consider using [Laravel Homestead](/docs/homestead). Homestead is a simple virtual machine designed for Laravel and [Vagrant](http://vagrantup.com). Since the Homestead Vagrant box is pre-packaged with all of the software you need to build robust PHP applications, you can create a virtualized, isolated development environment in seconds. Here is a list of some of the goodies included with Homestead:
51+
52+
- Nginx
53+
- PHP 5.5
54+
- MySQL
55+
- Redis
56+
- Memcached
57+
- Beanstalk
58+
59+
Don't worry, even though "virtualized" sounds complicated, it's painless. VirtualBox and Vagrant, which are Homestead's two dependencies, both include simple, graphical installers for all popular operating systems. Check out the [Homestead documentation](/docs/homestead) to get started.
60+
4561
<a name="routing"></a>
4662
## Routing
4763

@@ -171,3 +187,10 @@ Now that we have made the `users` available to our view, we can display them lik
171187
You may be wondering where to find our `echo` statements. When using Blade, you may echo data by surrounding it with double curly braces. It's a cinch. Now, you should be able to hit the `/users` route and see the names of your users displayed in the response.
172188

173189
This is just the beginning. In this tutorial, you've seen the very basics of Laravel, but there are so many more exciting things to learn. Keep reading through the documentation and dig deeper into the powerful features available to you in [Eloquent](/docs/eloquent) and [Blade](/docs/templates). Or, maybe you're more interested in [Queues](/docs/queues) and [Unit Testing](/docs/testing). Then again, maybe you want to flex your architecture muscles with the [IoC Container](/docs/ioc). The choice is yours!
190+
191+
<a name="deploying-your-application"></a>
192+
## Deploying Your Application
193+
194+
One of Laravel's goals is to make PHP application development enjoyable from download to deploy, and [Laravel Forge](https://forge.laravel.com) provides a simple way to deploy your Laravel applications onto blazing fast servers. Forge can configure and provision servers on DigitalOcean, Linode, Rackspace, and Amazon EC2. Like Homestead, all of the latest goodes are included: Nginx, PHP 5.5, MySQL, Postgres, Redis, Memcached, and more. Forge "Quick Deploy" can even deploy your code for you each time you push changes out to Github or Bitbucket!
195+
196+
On top of that, Forge can help you configure queue workers, SSL, Cron jobs, sub-domains, and more. For more information, visit the [Forge website](https://forge.laravel.com).

cn/releases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Laravel Cashier是一个简单的、富于表现力的库,它用来管理条
3838

3939
Artisan的“queue:work”命令现在支持“--daemon”选项,它用来启动一个“守护进程模式”的工人,这个模式使得工人在不需要重启框架的情况下继续工作。这会显著的减少CPU的使用率,其代价只是使得应用程序的部署过程稍显复杂。
4040

41-
在队列文档(/docs/queue#daemon-queue-workers)里能找到更多的队列工人相关的信息。
41+
在队列文档(/docs/queues#daemon-queue-workers)里能找到更多的队列工人相关的信息。
4242

4343
### 邮件API驱动
4444

cn/templates.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# 模板
2+
3+
- [控制器布局](#controller-layouts)
4+
- [Blade模板](#blade-templating)
5+
- [Blade模板控制结构](#other-blade-control-structures)
6+
- [扩展Blade](#extending-blade)
7+
8+
<a name="controller-layouts"></a>
9+
## 控制器布局
10+
11+
12+
在Laravel框架中使用模板的一种方法就是通过控制器布局。通过在控制器中指定`layout`属性,指定的视图就会被创建,并作为默认数据,在actions中返回。
13+
14+
#### 在控制器中定义布局(Layouts)
15+
16+
class UserController extends BaseController {
17+
18+
/**
19+
* The layout that should be used for responses.
20+
*/
21+
protected $layout = 'layouts.master';
22+
23+
/**
24+
* Show the user profile.
25+
*/
26+
public function showProfile()
27+
{
28+
$this->layout->content = View::make('user.profile');
29+
}
30+
31+
}
32+
33+
<a name="blade-templating"></a>
34+
## Blade模板
35+
36+
Blade是Laravel框架下的一个简单但又强大的模板引擎。 不同于控制器布局,Blade模板引擎由 _模板继承__模板片段_ 驱动。所有的Blade模板文件必须使用 `.blade.php` 文件扩展名。
37+
38+
#### 定义一个Blade布局
39+
40+
<!-- Stored in app/views/layouts/master.blade.php -->
41+
42+
<html>
43+
<body>
44+
@section('sidebar')
45+
This is the master sidebar.
46+
@show
47+
48+
<div class="container">
49+
@yield('content')
50+
</div>
51+
</body>
52+
</html>
53+
54+
#### 使用一个Blade布局
55+
56+
@extends('layouts.master')
57+
58+
@section('sidebar')
59+
@parent
60+
61+
<p>This is appended to the master sidebar.</p>
62+
@stop
63+
64+
@section('content')
65+
<p>This is my body content.</p>
66+
@stop
67+
68+
注意视图中片段只是简单的替换其`extend`的Blade布局中相应片段。通过在模板片段中使用`@parent`指令,布局的内容可以包含一个子视图,这样你就可以在布局片段中添加诸如侧边栏、底部信息等内容。
69+
70+
有时候,有些片段可能不能确定被定义了,你可以使用`@yield`结构给出一个默认值。如下,第二个值即是默认值。
71+
72+
@yield('section', 'Default Content');
73+
74+
<a name="other-blade-control-structures"></a>
75+
## 其他 Blade模板 控制结构
76+
77+
#### 输出数据
78+
79+
Hello, {{{ $name }}}.
80+
81+
The current UNIX timestamp is {{{ time() }}}.
82+
83+
#### 检测是否存在后输出数据
84+
85+
有时,你可能希望输出一个变量,但又不能确定这个变量是否被设置。直接点,你可能想这么做:
86+
87+
{{{ isset($name) ? $name : 'Default' }}}
88+
89+
然而,除了写一个三目运算符,Blade有如下简写方法:
90+
91+
{{{ $name or 'Default' }}}
92+
93+
#### 显示带有大括号的文本
94+
95+
如果你想显示带有大括号的字符串,你可以在文本前放`@`符号,这样会忽略Blade解析行为
96+
97+
@{{ This will not be processed by Blade }}
98+
99+
当然,用户提供的全部字符串都应该都被转义(主要对html标签,利用htmlentities编码转义)。如果想转义输出,你可以使用三个大括号语法:
100+
101+
Hello, {{{ $name }}}.
102+
103+
如果不希望数据被转义,可以使用双大括号语法:
104+
105+
Hello, {{ $name }}.
106+
107+
> **注意:** 一定要小心输出的用户提供的内容。使用三个大括号的语法能够直接输出内容中的HTML标签。
108+
109+
#### If标签
110+
111+
@if (count($records) === 1)
112+
I have one record!
113+
@elseif (count($records) > 1)
114+
I have multiple records!
115+
@else
116+
I don't have any records!
117+
@endif
118+
119+
@unless (Auth::check())
120+
You are not signed in.
121+
@endunless
122+
123+
#### 循环
124+
125+
@for ($i = 0; $i < 10; $i++)
126+
The current value is {{ $i }}
127+
@endfor
128+
129+
@foreach ($users as $user)
130+
<p>This is user {{ $user->id }}</p>
131+
@endforeach
132+
133+
@while (true)
134+
<p>I'm looping forever.</p>
135+
@endwhile
136+
137+
#### 包含子视图
138+
139+
@include('view.name')
140+
141+
你也可以传递数组数据到被包含的视图
142+
143+
@include('view.name', array('some'=>'data'))
144+
145+
#### 覆盖片段
146+
147+
默认的,片段是附加在先前存在的片段上,如果想覆盖一个片段的全部,可以使用`overwrite`标签
148+
149+
@extends('list.item.container')
150+
151+
@section('list.item.content')
152+
<p>This is an item of type {{ $item->type }}</p>
153+
@overwrite
154+
155+
#### 输出多语言
156+
157+
@lang('language.line')
158+
159+
@choice('language.line', 1);
160+
161+
#### 注释
162+
163+
{{-- This comment will not be in the rendered HTML --}}
164+
165+
<a name="extending-blade"></a>
166+
## 扩展Blade
167+
168+
Blade允许用户定义自己的控制结构。当一个Blade文件被编译后,会调用用户自定义的扩展,用来处理视图内容,从简单的`str_replace`操作,到很复杂的表达式,总之,你可以做任何事情。
169+
170+
Blade的编译器附带了帮助函数`createMatcher``createPlainMatcher`,这两个函数可以生成自定义指令。
171+
172+
`createPlainMatcher`函数主要用于没有参数传递的指令,类似`@endif``@stop`,而`createMatcher`则用于那些有参数传递的指令。
173+
174+
下面的例子创建`@datetime($var)`指令,它只是简单的对`$var`调用`->format()`方法:
175+
176+
Blade::extend(function($view, $compiler)
177+
{
178+
$pattern = $compiler->createMatcher('datetime');
179+
180+
return preg_replace($pattern, '$1<?php echo $2->format('m/d/Y H:i'); ?>', $view);
181+
});

0 commit comments

Comments
 (0)