3. Final Methods
Most of the time, allowing your classes to be extended
using inheritance is a good thing. It's part of what
makes object-oriented programming so powerful.
Occasionally, though, overriding certain methods of a
class can cause things to break easily, create security
issues, or make the resulting code overly complex.
When you wish to prevent a subclass from overriding
a superclass method, you can use the final keyword.
3
5. 5
Interface
An interface is an outline of what a particular
object can do. You will often hear that an
interface is a contract. This is true in as much
as an interface defines the public methods that
a class must implement.
Object interfaces allow you to create code
which specifies which methods a class must
implement, without having to define how these
methods are handled.
7. Abstract
7
An abstract class is a special type of class that can't
be instantiated — in other words, you can't create
objects from it. Instead, you create child classes
from the abstract class, and create objects from
those child classes instead.
An abstract class is designed to be used as a
template for creating classes.
An abstract class will have abstract methods which
are defined by the abstract keyword, these methods
are like the methods defined in the interface classes.
9. Interface vs Abstract
Interface Abstract
The Code
• abstract methods
• constants
• abstract methods
• constants
• concrete methods
• concrete variables
Access Modifiers • public
• public
• private
• protected
Number of Parents
Class can impelement
more than one interface
Class can inherit only
from one abstract class
9
10. What is template engine?
Template Engine, combines web templates to form
finished web pages, possibly using some data
source to customize the pages or present a large
amount of content on similar-looking pages.
As you know, the controller is responsible for
handling each request that comes into a Laravel
application. When a controller needs to generate
HTML, CSS or any other content, it hands the work
off to the templating engine.
10
12. Template
12
A template is simply a text file that can generate any
text-based format (HTML, XML, CSV, LaTeX ...). The
most familiar type of template is a PHP template - a text
file parsed by PHP that contains a mix of text and PHP
code.
13. Blade
Blade is the simple, yet powerful templating engine
provided with Laravel.
Unlike other popular PHP templating engines, Blade
does not restrict you from using plain PHP code in your
views. In fact, all Blade views are compiled into plain
PHP code and cached until they are modified, meaning
Blade adds essentially zero overhead to your
application.
14. Blade
Blade view files use the .blade.php file extension and
are typically stored in the resources/views directory.
Every template name also has two extensions that
specify the format and engine for that template.
Views contain the HTML served by your application
and separate your controller / application logic from
your presentation logic.
16. Template Inheritance
16
Extending a Layout:
When defining a child view,
use the Blade @extends
directive to specify which
layout the child view should
"inherit".
17. Routes & Blade Views
Blade views may be returned from routes using
the global view helper:
17
18. Components & Slots
18
Components and slots provide similar benefits to
sections and layouts; however, some may find the
mental model of components and slots easier to
understand.
20. Displaying Data
You may display data passed to your Blade views by
wrapping the variable in curly braces.
20
21. Displaying Data
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.
You can do:
21
22. 22
Displaying Data
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:
If you do not want your data to be escaped, you may use the
following syntax:
23. 23
Sharing Data with All Views
Occasionally, you may
need to share a piece of
data with all views that
are rendered by your
application.
24. 24
Blade & JavaScript
Framework
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:
25. 25
Blade & JavaScript
Framework
If you are displaying JavaScript variables in a large
portion of your template, you may wrap the HTML in the
@verbatim directive so that you do not have to prefix
each Blade echo statement with an @ symbol:
30. 30
Comments
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:
31. 31
Including Sub-Views
Blade’s @include directive allows you to
include a Blade view from within another view.
All variables that are available to the parent
view will be made available to the included
view: