You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: views.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -22,11 +22,11 @@ A simple view might look something like this:
22
22
23
23
Since this view is stored at `resources/views/greeting.php`, we may return it using the global `view` helper function like so:
24
24
25
-
Route::get('/', function () {
25
+
Route::get('/', function () {
26
26
return view('greeting', ['name' => 'James']);
27
27
});
28
28
29
-
As you can see, the first argument passed to the `view` helper corresponds to the name of the view file in the `resources/views` directory. The second argument passed to helper is an array of data that should be made available to the view. In this case, we are passing the `name` variable, which is displayed in the view by simply executing `echo` on the variable.
29
+
As you can see, the first argument passed to the `view` helper corresponds to the name of the view file in the `resources/views` directory. The second argument passed to helper is an array of data that should be made available to the view. In this case, we are passing the `name` variable, which is displayed in the view by executing `echo` on the variable.
30
30
31
31
Of course, views may also be nested within sub-directories of the `resources/views` directory. "Dot" notation may be used to reference nested views. For example, if your view is stored at `resources/views/admin/profile.php`, you may reference it like so:
32
32
@@ -54,12 +54,12 @@ As you saw in the previous examples, you may easily pass an array of data to vie
54
54
55
55
When passing information in this manner, `$data` should be an array with key/value pairs. Inside your view, you can then access each value using its corresponding key, such as `<?php echo $key; ?>`. As an alternative to passing a complete array of data to the `view` helper function, you may use the `with` method to add individual pieces of data to the view:
Occasionally, you may need to share a piece of data with all views that are rendered by your application. You may do so using the view factory's `share` method. Typically, you would place calls to `share` within a service provider's `boot` method. You are free to add them to the `AppServiceProvider` or generate a separate service provider to house them:
62
+
Occasionally, you may need to share a piece of data with all views that are rendered by your application. You may do so using the view factory's `share` method. Typically, you should place calls to `share` within a service provider's `boot` method. You are free to add them to the `AppServiceProvider` or generate a separate service provider to house them:
63
63
64
64
<?php
65
65
@@ -117,7 +117,7 @@ Let's register our view composers within a [service provider](/docs/{{version}}/
117
117
118
118
// Using Closure based composers...
119
119
view()->composer('dashboard', function ($view) {
120
-
120
+
//
121
121
});
122
122
}
123
123
@@ -140,7 +140,7 @@ Now that we have registered the composer, the `ProfileComposer@compose` method w
140
140
141
141
namespace App\Http\ViewComposers;
142
142
143
-
use Illuminate\Contracts\View\View;
143
+
use Illuminate\View\View;
144
144
use Illuminate\Users\Repository as UserRepository;
145
145
146
146
class ProfileComposer
@@ -176,7 +176,7 @@ Now that we have registered the composer, the `ProfileComposer@compose` method w
176
176
}
177
177
}
178
178
179
-
Just before the view is rendered, the composer's `compose` method is called with the `Illuminate\Contracts\View\View` instance. You may use the `with` method to bind data to the view.
179
+
Just before the view is rendered, the composer's `compose` method is called with the `Illuminate\View\View` instance. You may use the `with` method to bind data to the view.
180
180
181
181
> **Note:** All view composers are resolved via the [service container](/docs/{{version}}/container), so you may type-hint any dependencies you need within a composer's constructor.
0 commit comments