Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1bf96d

Browse files
committed
Igualando branchs ao upstream
1 parent 7aa9520 commit d1bf96d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1635
-1260
lines changed

artisan.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ To assign a shortcut when defining an option, you may specify it before the opti
158158

159159
email:send {user} {--Q|queue}
160160

161+
If you would like to define arguments or options to expect array inputs, you may use the `*` character:
162+
163+
email:send {user*}
164+
165+
email:send {user} {--id=*}
166+
161167
#### Input Descriptions
162168

163169
You may assign descriptions to input arguments and options by separating the parameter from the description using a colon:
@@ -176,8 +182,6 @@ You may assign descriptions to input arguments and options by separating the par
176182

177183
While your command is executing, you will obviously need to access the values for the arguments and options accepted by your command. To do so, you may use the `argument` and `option` methods:
178184

179-
To retrieve the value of an argument, use the `argument` method:
180-
181185
/**
182186
* Execute the console command.
183187
*
@@ -233,13 +237,13 @@ If you need to ask the user for a simple confirmation, you may use the `confirm`
233237

234238
#### Giving The User A Choice
235239

236-
The `anticipate` method can be used to provided autocompletion for possible choices. The user can still choose any answer, regardless of the choices.
240+
The `anticipate` method can be used to provide autocompletion for possible choices. The user can still choose any answer, regardless of the auto-completion hints:
237241

238242
$name = $this->anticipate('What is your name?', ['Taylor', 'Dayle']);
239243

240244
If you need to give the user a predefined set of choices, you may use the `choice` method. The user chooses the index of the answer, but the value of the answer will be returned to you. You may set the default value to be returned if nothing is chosen:
241245

242-
$name = $this->choice('What is your name?', ['Taylor', 'Dayle'], false);
246+
$name = $this->choice('What is your name?', ['Taylor', 'Dayle'], $default);
243247

244248
<a name="writing-output"></a>
245249
### Writing Output

authentication.md

Lines changed: 144 additions & 267 deletions
Large diffs are not rendered by default.

authorization.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
In addition to providing [authentication](/docs/{{version}}/authentication) services out of the box, Laravel also provides a simple way to organize authorization logic and control access to resources. There are a variety of methods and helpers to assist you in organizing your authorization logic, and we'll cover each of them in this document.
2020

21-
> **Note:** Authorization was added in Laravel 5.1.11, please refer to the [upgrade guide](/docs/{{version}}/upgrade) before integrating these features into your application.
22-
2321
<a name="defining-abilities"></a>
2422
## Defining Abilities
2523

billing.md

Lines changed: 64 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,53 @@ Laravel Cashier provides an expressive, fluent interface to [Stripe's](https://s
2828

2929
First, add the Cashier package to your `composer.json` file and run the `composer update` command:
3030

31-
"laravel/cashier": "~5.0" (For Stripe SDK ~2.0, and Stripe APIs on 2015-02-18 version and later)
32-
"laravel/cashier": "~4.0" (For Stripe APIs on 2015-02-18 version and later)
33-
"laravel/cashier": "~3.0" (For Stripe APIs up to and including 2015-02-16 version)
31+
"laravel/cashier": "~6.0"
3432

3533
#### Service Provider
3634

3735
Next, register the `Laravel\Cashier\CashierServiceProvider` [service provider](/docs/{{version}}/providers) in your `app` configuration file.
3836

3937
#### Migration
4038

41-
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 run the command: `php artisan cashier:table users`.
39+
Before using Cashier, we'll need to prepare the database. We need to add several columns to your `users` table and create a new `subscriptions` table to hold all of our customer's subscriptions:
4240

43-
Once the migration has been created, simply run the `migrate` command.
41+
Schema::table('users', function ($table) {
42+
$table->string('stripe_id')->nullable();
43+
$table->string('card_brand')->nullable();
44+
$table->string('card_last_four')->nullable();
45+
});
46+
47+
Schema::create('subscriptions', function ($table) {
48+
$table->increments('id');
49+
$table->integer('user_id');
50+
$table->string('name');
51+
$table->string('stripe_id');
52+
$table->string('stripe_plan');
53+
$table->integer('quantity');
54+
$table->timestamp('trial_ends_at')->nullable();
55+
$table->timestamp('ends_at')->nullable();
56+
$table->timestamps();
57+
});
58+
59+
Once the migrations have been created, simply run the `migrate` command.
4460

4561
#### Model Setup
4662

47-
Next, add the `Billable` trait and appropriate date mutators to your model definition:
63+
Next, add the `Billable` trait to your model definition:
4864

4965
use Laravel\Cashier\Billable;
50-
use Laravel\Cashier\Contracts\Billable as BillableContract;
5166

52-
class User extends Model implements BillableContract
67+
class User extends Authenticatable
5368
{
5469
use Billable;
55-
56-
protected $dates = ['trial_ends_at', 'subscription_ends_at'];
5770
}
5871

59-
Adding the columns to your model's `$dates` property will instruct Eloquent to return the columns as Carbon / DateTime instances instead of raw strings.
60-
6172
#### Stripe Key
6273

6374
Finally, set your Stripe key in your `services.php` configuration file:
6475

6576
'stripe' => [
66-
'model' => 'User',
77+
'model' => App\User::class,
6778
'secret' => env('STRIPE_API_SECRET'),
6879
],
6980

@@ -73,25 +84,21 @@ Finally, set your Stripe key in your `services.php` configuration file:
7384
<a name="creating-subscriptions"></a>
7485
### Creating Subscriptions
7586

76-
To create a subscription, first retrieve an instance of your billable model, which typically will be an instance of `App\User`. Once you have retrieved the model instance, you may use the `subscription` method to manage the model's subscription:
87+
To create a subscription, first retrieve an instance of your billable model, which typically will be an instance of `App\User`. Once you have retrieved the model instance, you may use the `newSubscription` method to create the model's subscription:
7788

7889
$user = User::find(1);
7990

80-
$user->subscription('monthly')->create($creditCardToken);
81-
82-
The `create` 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.
83-
84-
If you want to implement trial periods, but are managing the trials entirely within your application instead of defining them within Stripe, you must manually set the trial end date:
91+
$user->newSubscription('main', 'monthly')->create($creditCardToken);
8592

86-
$user->trial_ends_at = Carbon::now()->addDays(14);
93+
The first argument passed to the `newSubscription` method should be the name of the subscription. If your application only offers a single subscription, you might call this `main` or `primary`. The second argument is the specific Stripe plan the user is subscribing to. This value should correspond to the plan's identifier in Stripe.
8794

88-
$user->save();
95+
The `create` 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.
8996

9097
#### Additional User Details
9198

9299
If you would like to specify additional customer details, you may do so by passing them as the second argument to the `create` method:
93100

94-
$user->subscription('monthly')->create($creditCardToken, [
101+
$user->newSubscription('main', 'monthly')->create($creditCardToken, [
95102
'email' => $email, 'description' => 'Our First Customer'
96103
]);
97104

@@ -101,7 +108,7 @@ To learn more about the additional fields supported by Stripe, check out Stripe'
101108

102109
If you would like to apply a coupon when creating the subscription, you may use the `withCoupon` method:
103110

104-
$user->subscription('monthly')
111+
$user->newSubscription('main', 'monthly')
105112
->withCoupon('code')
106113
->create($creditCardToken);
107114

@@ -110,15 +117,15 @@ If you would like to apply a coupon when creating the subscription, you may use
110117

111118
Once a user is subscribed to your application, you may easily check their subscription status using a variety of convenient methods. First, the `subscribed` method returns `true` if the user has an active subscription, even if the subscription is currently within its trial period:
112119

113-
if ($user->subscribed()) {
120+
if ($user->subscribed('main')) {
114121
//
115122
}
116123

117124
The `subscribed` method also makes a great candidate for a [route middleware](/docs/{{version}}/middleware), allowing you to filter access to routes and controllers based on the user's subscription status:
118125

119126
public function handle($request, Closure $next)
120127
{
121-
if ($request->user() && ! $request->user()->subscribed()) {
128+
if ($request->user() && ! $request->user()->subscribed('main')) {
122129
// This user is not a paying customer...
123130
return redirect('billing');
124131
}
@@ -128,7 +135,7 @@ The `subscribed` method also makes a great candidate for a [route middleware](/d
128135

129136
If you would like to determine if a user is still within their trial period, you may use the `onTrial` method. This method can be useful for displaying a warning to the user that they are still on their trial period:
130137

131-
if ($user->onTrial()) {
138+
if ($user->subscription('main')->onTrial()) {
132139
//
133140
}
134141

@@ -142,19 +149,13 @@ The `onPlan` method may be used to determine if the user is subscribed to a give
142149

143150
To determine if the user was once an active subscriber, but has cancelled their subscription, you may use the `cancelled` method:
144151

145-
if ($user->cancelled()) {
152+
if ($user->subscription('main')->cancelled()) {
146153
//
147154
}
148155

149156
You may also determine if a user has cancelled their subscription, but are still on their "grace period" until the subscription fully expires. For example, if a user cancels a subscription on March 5th that was originally scheduled to expire on March 10th, the user is on their "grace period" until March 10th. Note that the `subscribed` method still returns `true` during this time.
150157

151-
if ($user->onGracePeriod()) {
152-
//
153-
}
154-
155-
The `everSubscribed` method may be used to determine if the user has ever subscribed to a plan in your application:
156-
157-
if ($user->everSubscribed()) {
158+
if ($user->subscription('main')->onGracePeriod()) {
158159
//
159160
}
160161

@@ -165,43 +166,43 @@ After a user is subscribed to your application, they may occasionally want to ch
165166

166167
$user = App\User::find(1);
167168

168-
$user->subscription('premium')->swap();
169+
$user->subscription('main')->swap('stripe-plan-id');
170+
171+
If the user is on trial, the trial period will be maintained. Also, if a "quantity" exists for the subscription, that quantity will also be maintained. If you would like to invoice the customer immediately after swapping plans, use the `invoice` method:
169172

170-
If the user is on trial, the trial period will be maintained. Also, if a "quantity" exists for the subscription, that quantity will also be maintained. When swapping plans, you may also use the `prorate` method to indicate that the charges should be pro-rated. In addition, you may use the `swapAndInvoice` method to immediately invoice the user for the plan change:
173+
$user->subscription('main')->swap('stripe-plan-id');
171174

172-
$user->subscription('premium')
173-
->prorate()
174-
->swapAndInvoice();
175+
$user->invoice();
175176

176177
<a name="subscription-quantity"></a>
177178
### Subscription Quantity
178179

179-
Sometimes subscriptions are affected by "quantity". For example, your application might charge $10 per month **per user** on an account. To easily increment or decrement your subscription quantity, use the `increment` and `decrement` methods:
180+
Sometimes subscriptions are affected by "quantity". For example, your application might charge $10 per month **per user** on an account. To easily increment or decrement your subscription quantity, use the `incrementQuantity` and `decrementQuantity` methods:
180181

181182
$user = User::find(1);
182183

183-
$user->subscription()->increment();
184+
$user->subscription('main')->incrementQuantity();
184185

185186
// Add five to the subscription's current quantity...
186-
$user->subscription()->increment(5);
187+
$user->subscription('main')->incrementQuantity(5);
187188

188-
$user->subscription()->decrement();
189+
$user->subscription('main')->decrementQuantity();
189190

190191
// Subtract five to the subscription's current quantity...
191-
$user->subscription()->decrement(5);
192+
$user->subscription('main')->decrementQuantity(5);
192193

193194
Alternatively, you may set a specific quantity using the `updateQuantity` method:
194195

195-
$user->subscription()->updateQuantity(10);
196+
$user->subscription('main')->updateQuantity(10);
196197

197198
For more information on subscription quantities, consult the [Stripe documentation](https://stripe.com/docs/guides/subscriptions#setting-quantities).
198199

199200
<a name="subscription-taxes"></a>
200201
### Subscription Taxes
201202

202-
With Cashier, it's easy to provide the `tax_percent` value sent to Stripe. To specify the tax percentage a user pays on a subscription, implement the `getTaxPercent` method on your billable model, and return a numeric value between 0 and 100, with no more than 2 decimal places.
203+
With Cashier, it's easy to provide the `tax_percent` value sent to Stripe. To specify the tax percentage a user pays on a subscription, implement the `taxPercentage` method on your billable model, and return a numeric value between 0 and 100, with no more than 2 decimal places.
203204

204-
public function getTaxPercent() {
205+
public function taxPercentage() {
205206
return 20;
206207
}
207208

@@ -212,22 +213,22 @@ This enables you to apply a tax rate on a model-by-model basis, which may be hel
212213

213214
To cancel a subscription, simply call the `cancel` method on the user's subscription:
214215

215-
$user->subscription()->cancel();
216+
$user->subscription('main')->cancel();
216217

217-
When a subscription is cancelled, Cashier will automatically set the `subscription_ends_at` column in your database. This column is used to know when the `subscribed` method should begin returning `false`. For example, if a customer cancels a subscription on March 1st, but the subscription was not scheduled to end until March 5th, the `subscribed` method will continue to return `true` until March 5th.
218+
When a subscription is cancelled, Cashier will automatically set the `ends_at` column in your database. This column is used to know when the `subscribed` method should begin returning `false`. For example, if a customer cancels a subscription on March 1st, but the subscription was not scheduled to end until March 5th, the `subscribed` method will continue to return `true` until March 5th.
218219

219220
You may determine if a user has cancelled their subscription but are still on their "grace period" using the `onGracePeriod` method:
220221

221-
if ($user->onGracePeriod()) {
222+
if ($user->subscription('main')->onGracePeriod()) {
222223
//
223224
}
224225

225226
<a name="resuming-subscriptions"></a>
226227
### Resuming Subscriptions
227228

228-
If a user has cancelled their subscription and you wish to resume it, use the `resume` method:
229+
If a user has cancelled their subscription and you wish to resume it, use the `resume` method. The user **must** still be on their grace period in order to resume a subscription:
229230

230-
$user->subscription('monthly')->resume($creditCardToken);
231+
$user->subscription('main')->resume();
231232

232233
If the user cancels a subscription and then resumes that subscription before the subscription has fully expired, they will not be billed immediately. Instead, their subscription will simply be re-activated, and they will be billed on the original billing cycle.
233234

@@ -239,7 +240,10 @@ If the user cancels a subscription and then resumes that subscription before the
239240

240241
What if a customer's credit card expires? No worries - Cashier includes a Webhook controller that can easily cancel the customer's subscription for you. Just point a route to the controller:
241242

242-
Route::post('stripe/webhook', '\Laravel\Cashier\WebhookController@handleWebhook');
243+
Route::post(
244+
'stripe/webhook',
245+
'\Laravel\Cashier\Http\Controllers\WebhookController@handleWebhook'
246+
);
243247

244248
That's it! Failed payments will be captured and handled by the controller. The controller will cancel the customer's subscription when Stripe determines the subscription has failed (normally after three failed payment attempts). Don't forget: you will need to configure the webhook URI in your Stripe control panel settings.
245249

@@ -258,7 +262,7 @@ If you have additional Stripe webhook events you would like to handle, simply ex
258262

259263
namespace App\Http\Controllers;
260264

261-
use Laravel\Cashier\WebhookController as BaseController;
265+
use Laravel\Cashier\Http\Controllers\WebhookController as BaseController;
262266

263267
class WebhookController extends BaseController
264268
{
@@ -308,8 +312,8 @@ When listing the invoices for the customer, you may use the invoice's helper met
308312
<table>
309313
@foreach ($invoices as $invoice)
310314
<tr>
311-
<td>{{ $invoice->dateString() }}</td>
312-
<td>{{ $invoice->dollars() }}</td>
315+
<td>{{ $invoice->date()->toFormattedDateString() }}</td>
316+
<td>{{ $invoice->total() }}</td>
313317
<td><a href="/user/invoice/{{ $invoice->id }}">Download</a></td>
314318
</tr>
315319
@endforeach
@@ -318,6 +322,10 @@ When listing the invoices for the customer, you may use the invoice's helper met
318322
<a name="generating-invoice-pdfs"></a>
319323
#### Generating Invoice PDFs
320324

325+
Before generating invoice PDFs, you need to install the `dompdf` PHP library:
326+
327+
composer require dompdf/dompdf
328+
321329
From within a route or controller, use the `downloadInvoice` method to generate a PDF download of the invoice. This method will automatically generate the proper HTTP response to send the download to the browser:
322330

323331
Route::get('user/invoice/{invoice}', function ($invoiceId) {

blade.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [Extending A Layout](#extending-a-layout)
77
- [Displaying Data](#displaying-data)
88
- [Control Structures](#control-structures)
9+
- [Stacks](#stacks)
910
- [Service Injection](#service-injection)
1011
- [Extending Blade](#extending-blade)
1112

@@ -202,6 +203,23 @@ Blade also allows you to define comments in your views. However, unlike HTML com
202203

203204
{{-- This comment will not be present in the rendered HTML --}}
204205

206+
<a name="stacks"></a>
207+
## Stacks
208+
209+
Blade also allows you to push to named stacks which can be rendered somewhere else in another view or layout:
210+
211+
@push('scripts')
212+
<script src="/example.js"></script>
213+
@endpush
214+
215+
You may push to the same stack as many times as needed. To render a stack, use the `@stack` syntax:
216+
217+
<head>
218+
<!-- Head Contents -->
219+
220+
@stack('scripts')
221+
</head>
222+
205223
<a name="service-injection"></a>
206224
## Service Injection
207225

0 commit comments

Comments
 (0)