Tutorial by Examples

Views, in an MVC pattern, contain the logic on how to present data to the user. In a web application, typically they are used to generate the HTML output that is sent back to users with each response. By default, views in Laravel are stored in the resources/views directory. A view can be called u...
Blade provides convenient syntax for common PHP control structures. Each of the control structures begins with @[structure] and ends with @[endstructure]. Notice that within the tags, we are just typing normal HTML and including variables with the Blade syntax. Conditionals 'If' statements @if...
Any PHP expression within double curly braces {{ $variable }} will be echoed after being run through the e helper function. (So html special characters (<, >, ", ', &) are safely replaced for the corresponding html entities.) (The PHP expression must evaluate to string, otherwise an ...
With Blade, you can also include partial views (called 'partials') directly into a page like so: @include('includes.info', ['title' => 'Information Station']) The code above will include the view at 'views/includes/info.blade.php'. It will also pass in a variable $title having value 'Informat...
A layout is a view file, which is extended by other views which inject blocks of code into their parent. For example: parent.blade.php: <html> <head> <style type='text/css'> @yield('styling') </style> </head> <body> ...
Sometimes you need to set the same data in many of your views. Using View::share // "View" is the View Facade View::share('shareddata', $data); After this, the contents of $data will be available in all views under the name $shareddata. View::share is typically called in a service p...
Although it might not be proper to do such thing in a view if you intend to separate concerns strictly, the php Blade directive allows a way to execute PHP code, for instance, to set a variable: @php($varName = 'Enter content ') (same as:) @php $varName = 'Enter content '; @endphp late...

Page 1 of 1