Skip to content

Commit dc82ee4

Browse files
committed
同步英文文档,已对存在中文文档进行同步
1 parent fb51940 commit dc82ee4

18 files changed

+222
-47
lines changed

billing.md

+30-12
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/releases.md

+1-1
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/upgrade.md

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Laravel 4.2需要PHP 5.4.0或更高版本。
2020

2121
这个设置可以用来控制Laravel加密功能使用默认密钥。
2222

23+
> **Note:** In Laravel 4.2, the default cipher is `MCRYPT_RIJNDAEL_128` (AES), which is considered to be the most secure cipher. Changing the cipher back to `MCRYPT_RIJNDAEL_256` is required to decrypt cookies/values that were encrypted in Laravel <= 4.1
24+
2325
### 软删除模型现在的使用特性
2426

2527
如果你正在使用软删除模型,“softDeletes”属性已经被删除了。现在你应该使用“SoftDeletingTrait”属性,像下面这样:
@@ -40,6 +42,8 @@ Laravel 4.2需要PHP 5.4.0或更高版本。
4042

4143
所有软删除操作的API保持不变。
4244

45+
> **Note:** The `SoftDeletingTrait` can not be applied on a base model. It must be used on an actual model class.
46+
4347
### 重命名的视图/分页环境
4448

4549
如果你直接的引用了“Illuminate\View\Environment”类或“Illuminate\Pagination\Environment”类,升级你的代码,用“Illuminate\View\Factory”和“Illuminate\Pagination\Factory”来替代。原来的两个类已经被重命名,以更好地反映其功能。
@@ -50,6 +54,12 @@ Laravel 4.2需要PHP 5.4.0或更高版本。
5054

5155
abstract public function getPageLinkWrapper($url, $page, $rel = null);
5256

57+
### Iron.Io Queue Encryption
58+
59+
If you are using the Iron.io queue driver, you will need to add a new `encrypt` option to your queue configuration file:
60+
61+
'encrypt' => true
62+
5363
<a name="upgrade-4.1.29"></a>
5464
## 从小于等于4.1.x升级到4.1.29
5565

commands.md

+9
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ If your command is registered in the application [IoC container](/docs/ioc), you
129129

130130
Artisan::resolve('binding.name');
131131

132+
#### Registering Commands In A Service Provider
133+
134+
If you need to register commands from within a service provider, you should call the `commands` method from the provider's `boot` method, passing the [IoC container](/docs/ioc) binding for the command:
135+
136+
public function boot()
137+
{
138+
$this->commands('command.binding');
139+
}
140+
132141
<a name="calling-other-commands"></a>
133142
## Calling Other Commands
134143

contributing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Contribution Guidelines
22

3-
If you are submitting documentation for the **current stable release**, submit it to the corresponding branch. For example, documentation for Laravel 4.1 would be submitted to the `4.1` branch. Documentation intended for the next release of Laravel should be submitted to the `master` branch.
3+
If you are submitting documentation for the **current stable release**, submit it to the corresponding branch. For example, documentation for Laravel 4.2 would be submitted to the `4.2` branch. Documentation intended for the next release of Laravel should be submitted to the `master` branch.

controllers.md

+22
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ The `controller` method accepts two arguments. The first is the base URI the con
140140
{
141141
//
142142
}
143+
144+
public function anyLogin()
145+
{
146+
//
147+
}
143148

144149
}
145150

@@ -195,6 +200,23 @@ By default, all resource controller actions have a route name; however, you can
195200
Route::resource('photo', 'PhotoController',
196201
array('names' => array('create' => 'photo.build')));
197202

203+
#### Handling Nested Resource Controllers
204+
205+
To "nest" resource controllers, use "dot" notation in your route declaration:
206+
207+
Route::resource('photos.comments', 'PhotoCommentController');
208+
209+
This route will register a "nested" resource that may be accessed with URLs like the following: `photos/{photoResource}/comments/{commentResource}`.
210+
211+
class PhotoCommentController extends BaseController {
212+
213+
public function show($photoId, $commentId)
214+
{
215+
//
216+
}
217+
218+
}
219+
198220
#### Adding Additional Routes To Resource Controllers
199221

200222
If it becomes necessary for you to add additional routes to a resource controller beyond the default resource routes, you should define those routes before your call to `Route::resource`:

eloquent.md

+78-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Soft Deleting](#soft-deleting)
88
- [Timestamps](#timestamps)
99
- [Query Scopes](#query-scopes)
10+
- [Global Scopes](#global-scopes)
1011
- [Relationships](#relationships)
1112
- [Querying Relations](#querying-relations)
1213
- [Eager Loading](#eager-loading)
@@ -373,6 +374,70 @@ Then pass the parameter into the scope call:
373374

374375
$users = User::ofType('member')->get();
375376

377+
<a name="global-scopes"></a>
378+
## Global Scopes
379+
380+
Sometimes you may wish to define a scope that applies to all queries performed on a model. In essence, this is how Eloquent's own "soft delete" feature works. Global scopes are defined using a combination of PHP traits and an implementation of `Illuminate\Database\Eloquent\ScopeInterface`.
381+
382+
First, let's define a trait. For this example, we'll use the `SoftDeletingTrait` that ships with Laravel:
383+
384+
trait SoftDeletingTrait {
385+
386+
/**
387+
* Boot the soft deleting trait for a model.
388+
*
389+
* @return void
390+
*/
391+
public static function bootSoftDeletingTrait()
392+
{
393+
static::addGlobalScope(new SoftDeletingScope);
394+
}
395+
396+
}
397+
398+
If an Eloquent model uses a trait that has a method matching the `bootNameOfTrait` naming convention, that trait method will be called when the Eloquent model is booted, giving you an opportunity to register a global scope, or do anything else you want. A scope must implement `ScopeInterface`, which specifies two methods: `apply` and `remove`.
399+
400+
The `apply` method receives an `Illuminate\Database\Eloquent\Builder` query builder object, and is responsible for adding any additional `where` clauses that the scope wishes to add. The `remove` method also receives a `Builder` object and is responsible for reversing the action taken by `apply`. In other words, `remove` should remove the `where` clause (or any other clause) that was added. So, for our `SoftDeletingScope`, the methods look something like this:
401+
402+
/**
403+
* Apply the scope to a given Eloquent query builder.
404+
*
405+
* @param \Illuminate\Database\Eloquent\Builder $builder
406+
* @return void
407+
*/
408+
public function apply(Builder $builder)
409+
{
410+
$model = $builder->getModel();
411+
412+
$builder->whereNull($model->getQualifiedDeletedAtColumn());
413+
}
414+
415+
/**
416+
* Remove the scope from the given Eloquent query builder.
417+
*
418+
* @param \Illuminate\Database\Eloquent\Builder $builder
419+
* @return void
420+
*/
421+
public function remove(Builder $builder)
422+
{
423+
$column = $builder->getModel()->getQualifiedDeletedAtColumn();
424+
425+
$query = $builder->getQuery();
426+
427+
foreach ((array) $query->wheres as $key => $where)
428+
{
429+
// If the where clause is a soft delete date constraint, we will remove it from
430+
// the query and reset the keys on the wheres. This allows this developer to
431+
// include deleted model in a relationship result set that is lazy loaded.
432+
if ($this->isSoftDeleteConstraint($where, $column))
433+
{
434+
unset($query->wheres[$key]);
435+
436+
$query->wheres = array_values($query->wheres);
437+
}
438+
}
439+
}
440+
376441
<a name="relationships"></a>
377442
## Relationships
378443

@@ -835,6 +900,18 @@ You will often need to insert new related models. For example, you may wish to i
835900

836901
In this example, the `post_id` field will automatically be set on the inserted comment.
837902

903+
If you need to save multiple related models:
904+
905+
$comments = array(
906+
new Comment(array('message' => 'A new comment.')),
907+
new Comment(array('message' => 'Another comment.')),
908+
new Comment(array('message' => 'The latest comment.'))
909+
);
910+
911+
$post = Post::find(1);
912+
913+
$post->comments()->saveMany($comments);
914+
838915
### Associating Models (Belongs To)
839916

840917
When updating a `belongsTo` relationship, you may use the `associate` method. This method will set the foreign key on the child model:
@@ -1069,7 +1146,7 @@ Mutators are declared in a similar fashion:
10691146
<a name="date-mutators"></a>
10701147
## Date Mutators
10711148

1072-
By default, Eloquent will convert the `created_at`, `updated_at`, and `deleted_at` columns to instances of [Carbon](https://github.com/briannesbitt/Carbon), which provides an assortment of helpful methods, and extends the native PHP `DateTime` class.
1149+
By default, Eloquent will convert the `created_at` and `updated_at` columns to instances of [Carbon](https://github.com/briannesbitt/Carbon), which provides an assortment of helpful methods, and extends the native PHP `DateTime` class.
10731150

10741151
You may customize which fields are automatically mutated, and even completely disable this mutation, by overriding the `getDates` method of the model:
10751152

events.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,7 @@ Using the `queue` and `flush` methods, you may "queue" an event for firing, but
110110

111111
Event::queue('foo', array($user));
112112

113-
#### Registering An Event Flusher
114-
115-
Event::flusher('foo', function($user)
116-
{
117-
//
118-
});
119-
120-
Finally, you may run the "flusher" and flush all queued events using the `flush` method:
113+
You may run the "flusher" and flush all queued events using the `flush` method:
121114

122115
Event::flush('foo');
123116

extending.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Extending Laravel with a custom session driver is just as easy as extending the
8585

8686
### Where To Extend The Session
8787

88-
Session extensions need to be registered differently than other extensions like Cache and Auth. Since sessions are started very early in the request-lifecycle, registering the extensions in a `start` file will happen be too late. Instead, a [service provider](/docs/ioc#service-providers) will be needed. You should place your session extension code in the `register` method of your service provider, and the provider should be placed **below** the default `Illuminate\Session\SessionServiceProvider` in the `providers` configuration array.
88+
Session extensions need to be registered differently than other extensions like Cache and Auth. Since sessions are started very early in the request-lifecycle, registering the extensions in a `start` file will happen too late. Instead, a [service provider](/docs/ioc#service-providers) will be needed. You should place your session extension code in the `register` method of your service provider, and the provider should be placed **below** the default `Illuminate\Session\SessionServiceProvider` in the `providers` configuration array.
8989

9090
### Writing The Session Extension
9191

@@ -139,13 +139,19 @@ Let's take a look at the `UserProviderInterface`:
139139
interface UserProviderInterface {
140140

141141
public function retrieveById($identifier);
142+
public function retrieveByToken($identifier, $token);
143+
public function updateRememberToken(UserInterface $user, $token);
142144
public function retrieveByCredentials(array $credentials);
143145
public function validateCredentials(UserInterface $user, array $credentials);
144146

145147
}
146148

147149
The `retrieveById` function typically receives a numeric key representing the user, such as an auto-incrementing ID from a MySQL database. The `UserInterface` implementation matching the ID should be retrieved and returned by the method.
148150

151+
The `retrieveByToken` function retrieves a user by their unique `$identifier` and "remember me" `$token`, stored in a field `remember_token`. As with with previous method, the `UserInterface` implementation should be returned.
152+
153+
The `updateRememberToken` method updates the `$user` field `remember_token` with the new `$token`. The new token can be either a fresh token, assigned on successfull "remember me" login attempt, or a null when user is logged out.
154+
149155
The `retrieveByCredentials` method receives the array of credentials passed to the `Auth::attempt` method when attempting to sign into an application. The method should then "query" the underlying persistent storage for the user matching those credentials. Typically, this method will run a query with a "where" condition on `$credentials['username']`. **This method should not attempt to do any password validation or authentication.**
150156

151157
The `validateCredentials` method should compare the given `$user` with the `$credentials` to authenticate the user. For example, this method might compare the `$user->getAuthPassword()` string to a `Hash::make` of `$credentials['password']`.

mail.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To use the Mailgun driver, set the `driver` option to `mailgun` in your `app/con
2828

2929
#### Mandrill Driver
3030

31-
To use the Mailgun driver, set the `driver` option to `mandrill` in your `app/config/mail.php` configuration file. Next, create an `app/config/services.php` configuration file if one does not already exist for your project. Verify that it contains the following options:
31+
To use the Mandrill driver, set the `driver` option to `mandrill` in your `app/config/mail.php` configuration file. Next, create an `app/config/services.php` configuration file if one does not already exist for your project. Verify that it contains the following options:
3232

3333
'mandrill' => array(
3434
'secret' => 'your-mandrill-key',

pagination.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ There are several ways to paginate items. The simplest is by using the `paginate
2222

2323
$users = DB::table('users')->paginate(15);
2424

25+
> **Note:** Currently, pagination operations that use a `groupBy` statement cannot be executed efficiently by Laravel. If you need to use a `groupBy` with a paginated result set, it is recommended that you query the database manually and use `Paginator::make`.
26+
2527
#### Paginating An Eloquent Model
2628

2729
You may also paginate [Eloquent](/docs/eloquent) models:
@@ -101,7 +103,7 @@ This method call will generate URLs that look something like this:
101103
<a name="converting-to-json"></a>
102104
## Converting To JSON
103105

104-
The `Paginator` class implements the `Illuminate\Support\Contracts\JsonableInterface` contract and exposes the `toJson` method. You can may also convert a `Paginator` instance to JSON by returning it from a route. The JSON'd form of the instance will include some "meta" information such as `total`, `current_page`, `last_page`, `from`, and `to`. The instance's data will be available via the `data` key in the JSON array.
106+
The `Paginator` class implements the `Illuminate\Support\Contracts\JsonableInterface` contract and exposes the `toJson` method. You may also convert a `Paginator` instance to JSON by returning it from a route. The JSON'd form of the instance will include some "meta" information such as `total`, `current_page`, `last_page`, `from`, and `to`. The instance's data will be available via the `data` key in the JSON array.
105107

106108
<a name="custom-presenters"></a>
107109
## Custom Presenters

0 commit comments

Comments
 (0)