Skip to content

Commit 75651ca

Browse files
author
= Geo =
committed
replace all tabs with spaces (PSR-2)
1 parent ffe5123 commit 75651ca

Some content is hidden

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

47 files changed

+5302
-5302
lines changed

authentication.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ You will need to provide an HTML view for the password reset request form. This
404404
{!! csrf_field() !!}
405405

406406
<div>
407-
Email
407+
Email
408408
<input type="email" name="email" value="{{ old('email') }}">
409409
</div>
410410

billing.md

+124-124
Large diffs are not rendered by default.

blade.md

+107-107
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
- [Introduction](#introduction)
44
- [Template Inheritance](#template-inheritance)
5-
- [Defining A Layout](#defining-a-layout)
6-
- [Extending A Layout](#extending-a-layout)
5+
- [Defining A Layout](#defining-a-layout)
6+
- [Extending A Layout](#extending-a-layout)
77
- [Displaying Data](#displaying-data)
88
- [Control Structures](#control-structures)
99
- [Service Injection](#service-injection)
@@ -22,22 +22,22 @@ Blade is the simple, yet powerful templating engine provided with Laravel. Unlik
2222

2323
Two of the primary benefits of using Blade are _template inheritance_ and _sections_. To get started, let's take a look at a simple example. First, we will examine a "master" page layout. Since most web applications maintain the same general layout across various pages, it's convenient to define this layout as a single Blade view:
2424

25-
<!-- Stored in resources/views/layouts/master.blade.php -->
25+
<!-- Stored in resources/views/layouts/master.blade.php -->
2626

27-
<html>
28-
<head>
29-
<title>App Name - @yield('title')</title>
30-
</head>
31-
<body>
32-
@section('sidebar')
33-
This is the master sidebar.
34-
@show
27+
<html>
28+
<head>
29+
<title>App Name - @yield('title')</title>
30+
</head>
31+
<body>
32+
@section('sidebar')
33+
This is the master sidebar.
34+
@show
3535

36-
<div class="container">
37-
@yield('content')
38-
</div>
39-
</body>
40-
</html>
36+
<div class="container">
37+
@yield('content')
38+
</div>
39+
</body>
40+
</html>
4141

4242
As you can see, this file contains typical HTML mark-up. However, take note of the `@section` and `@yield` directives. The `@section` directive, as the name implies, defines a section of content, while the `@yield` directive is used to display the contents of a given section.
4343

@@ -48,76 +48,76 @@ Now that we have defined a layout for our application, let's define a child page
4848

4949
When defining a child page, you may use the Blade `@extends` directive to specify which layout the child page should "inherit". Views which `@extends` a Blade layout may inject content into the layout's sections using `@section` directives. Remember, as seen in the example above, the contents of these sections will be displayed in the layout using `@yield`:
5050

51-
<!-- Stored in resources/views/layouts/child.blade.php -->
51+
<!-- Stored in resources/views/layouts/child.blade.php -->
5252

53-
@extends('layouts.master')
53+
@extends('layouts.master')
5454

55-
@section('title', 'Page Title')
55+
@section('title', 'Page Title')
5656

57-
@section('sidebar')
58-
@@parent
57+
@section('sidebar')
58+
@@parent
5959

60-
<p>This is appended to the master sidebar.</p>
61-
@endsection
60+
<p>This is appended to the master sidebar.</p>
61+
@endsection
6262

63-
@section('content')
64-
<p>This is my body content.</p>
65-
@endsection
63+
@section('content')
64+
<p>This is my body content.</p>
65+
@endsection
6666

6767
In this example, the `sidebar` section is utilizing the `@@parent` directive to append (rather than overwriting) content to the layout's sidebar. The `@@parent` directive will be replaced by the content of the layout when the view is rendered.
6868

6969
Of course, just like plain PHP views, Blade views may be returned from routes using the global `view` helper function:
7070

71-
Route::get('blade', function () {
72-
return view('child');
73-
});
71+
Route::get('blade', function () {
72+
return view('child');
73+
});
7474

7575
<a name="displaying-data"></a>
7676
## Displaying Data
7777

7878
You may display data passed to your Blade views by wrapping the variable in "curly" braces. For example, given the following route:
7979

80-
Route::get('greeting', function () {
81-
return view('welcome', ['name' => 'Samantha']);
82-
});
80+
Route::get('greeting', function () {
81+
return view('welcome', ['name' => 'Samantha']);
82+
});
8383

8484
You may display the contents of the `name` variable like so:
8585

86-
Hello, {{ $name }}.
86+
Hello, {{ $name }}.
8787

8888
Of course, you are not limited to displaying the contents of the variables passed to the view. You may also echo the results of any PHP function. In fact, you can put any PHP code you wish inside of a Blade echo statement:
8989

90-
The current UNIX timestamp is {{ time() }}.
90+
The current UNIX timestamp is {{ time() }}.
9191

9292
> **Note:** Blade `{{ }}` statements are automatically sent through PHP's `htmlentities` function to prevent XSS attacks.
9393
9494
#### Blade & JavaScript Frameworks
9595

9696
Since many JavaScript frameworks also use "curly" braces to indicate a given expression should be displayed in the browser, you may use the `@` symbol to inform the Blade rendering engine an expression should remain untouched. For example:
9797

98-
<h1>Laravel</h1>
98+
<h1>Laravel</h1>
9999

100-
Hello, @{{ name }}.
100+
Hello, @{{ name }}.
101101

102102
In this example, the `@` symbol will be removed by Blade; however, `{{ name }}` expression will remain untouched by the Blade engine, allowing it to instead be rendered by your JavaScript framework.
103103

104104
#### Echoing Data If It Exists
105105

106106
Sometimes you may wish to echo a variable, but you aren't sure if the variable has been set. We can express this in verbose PHP code like so:
107107

108-
{{ isset($name) ? $name : 'Default' }}
108+
{{ isset($name) ? $name : 'Default' }}
109109

110110
However, instead of writing a ternary statement, Blade provides you with the following convenient short-cut:
111111

112-
{{ $name or 'Default' }}
112+
{{ $name or 'Default' }}
113113

114114
In this example, if the `$name` variable exists, its value will be displayed. However, if it does not exist, the word `Default` will be displayed.
115115

116116
#### Displaying Unescaped Data
117117

118118
By default, Blade `{{ }}` statements are automatically sent through PHP's `htmlentities` function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:
119119

120-
Hello, {!! $name !!}.
120+
Hello, {!! $name !!}.
121121

122122
> **Note:** Be very careful when echoing content that is supplied by users of your application. Always use the double curly brace syntax to escape any HTML entities in the content.
123123
@@ -130,74 +130,74 @@ In addition to template inheritance and displaying data, Blade also provides con
130130

131131
You may construct `if` statements using the `@if`, `@elseif`, `@else`, and `@endif` directives. These directives function identically to their PHP counterparts:
132132

133-
@if (count($records) === 1)
134-
I have one record!
135-
@elseif (count($records) > 1)
136-
I have multiple records!
137-
@else
138-
I don't have any records!
139-
@endif
133+
@if (count($records) === 1)
134+
I have one record!
135+
@elseif (count($records) > 1)
136+
I have multiple records!
137+
@else
138+
I don't have any records!
139+
@endif
140140

141141
For convenience, Blade also provides an `@unless` directive:
142142

143-
@unless (Auth::check())
144-
You are not signed in.
145-
@endunless
143+
@unless (Auth::check())
144+
You are not signed in.
145+
@endunless
146146

147147
#### Loops
148148

149149
In addition to conditional statements, Blade provides simple directives for working with PHP's supported loop structures. Again, each of these directives functions identically to their PHP counterparts:
150150

151-
@for ($i = 0; $i < 10; $i++)
152-
The current value is {{ $i }}
153-
@endfor
151+
@for ($i = 0; $i < 10; $i++)
152+
The current value is {{ $i }}
153+
@endfor
154154

155-
@foreach ($users as $user)
156-
<p>This is user {{ $user->id }}</p>
157-
@endforeach
155+
@foreach ($users as $user)
156+
<p>This is user {{ $user->id }}</p>
157+
@endforeach
158158

159-
@forelse ($users as $user)
160-
<li>{{ $user->name }}</li>
161-
@empty
162-
<p>No users</p>
163-
@endforelse
159+
@forelse ($users as $user)
160+
<li>{{ $user->name }}</li>
161+
@empty
162+
<p>No users</p>
163+
@endforelse
164164

165-
@while (true)
166-
<p>I'm looping forever.</p>
167-
@endwhile
165+
@while (true)
166+
<p>I'm looping forever.</p>
167+
@endwhile
168168

169169
#### Including Sub-Views
170170

171171
Blade's `@include` directive, allows you to easily include a Blade view from within an existing view. All variables that are available to the parent view will be made available to the included view:
172172

173-
<div>
174-
@include('shared.errors')
173+
<div>
174+
@include('shared.errors')
175175

176-
<form>
177-
<!-- Form Contents -->
178-
</form>
179-
</div>
176+
<form>
177+
<!-- Form Contents -->
178+
</form>
179+
</div>
180180

181181
Even though the included view will inherit all data available in the parent view, you may also pass an array of extra data to the included view:
182182

183-
@include('view.name', ['some' => 'data'])
183+
@include('view.name', ['some' => 'data'])
184184

185185
#### Comments
186186

187187
Blade also allows you to define comments in your views. However, unlike HTML comments, Blade comments are not included in the HTML returned by your application:
188188

189-
{{-- This comment will not be present in the rendered HTML --}}
189+
{{-- This comment will not be present in the rendered HTML --}}
190190

191191
<a name="service-injection"></a>
192192
## Service Injection
193193

194194
The `@inject` directive may be used to retrieve a service from the Laravel [service container](/docs/{{version}}/container). The first argument passed to `@inject` is the name of the variable the service will be placed into, while the second argument is the class / interface name of the service you wish to resolve:
195195

196-
@inject('metrics', 'App\Services\MetricsService')
196+
@inject('metrics', 'App\Services\MetricsService')
197197

198-
<div>
199-
Monthly Revenue: {{ $metrics->monthlyRevenue() }}.
200-
</div>
198+
<div>
199+
Monthly Revenue: {{ $metrics->monthlyRevenue() }}.
200+
</div>
201201

202202
<a name="extending-blade"></a>
203203
## Extending Blade
@@ -206,40 +206,40 @@ Blade even allows you to define your own custom directives. You can use the `dir
206206

207207
The following example creates a `@datetime($var)` directive which formats a given `$var`:
208208

209-
<?php
210-
211-
namespace App\Providers;
212-
213-
use Blade;
214-
use Illuminate\Support\ServiceProvider;
215-
216-
class AppServiceProvider extends ServiceProvider
217-
{
218-
/**
219-
* Perform post-registration booting of services.
220-
*
221-
* @return void
222-
*/
223-
public function boot()
224-
{
225-
Blade::directive('datetime', function($expression) {
226-
return "<?php echo with{$expression}->format('m/d/Y H:i'); ?>";
227-
});
228-
}
229-
230-
/**
231-
* Register bindings in the container.
232-
*
233-
* @return void
234-
*/
235-
public function register()
236-
{
237-
//
238-
}
239-
}
209+
<?php
210+
211+
namespace App\Providers;
212+
213+
use Blade;
214+
use Illuminate\Support\ServiceProvider;
215+
216+
class AppServiceProvider extends ServiceProvider
217+
{
218+
/**
219+
* Perform post-registration booting of services.
220+
*
221+
* @return void
222+
*/
223+
public function boot()
224+
{
225+
Blade::directive('datetime', function($expression) {
226+
return "<?php echo with{$expression}->format('m/d/Y H:i'); ?>";
227+
});
228+
}
229+
230+
/**
231+
* Register bindings in the container.
232+
*
233+
* @return void
234+
*/
235+
public function register()
236+
{
237+
//
238+
}
239+
}
240240

241241
As you can see, Laravel's `with` helper function was used in this directive. The `with` helper simply returns the object / value it is given, allowing for convenient method chaining. The final PHP generated by this directive will be:
242242

243-
<?php echo with($var)->format('m/d/Y H:i'); ?>
243+
<?php echo with($var)->format('m/d/Y H:i'); ?>
244244

245245

0 commit comments

Comments
 (0)