Basic research on Laravel

Tram Ho

The basic commands:

  • See the php version

  • See the php path

After this command, see the path of the format: /usr/bin/php , this type is used by default php has been installed on the machine. change the default by going to ~/.bash_profile edit the path like this: export PATH=/Applications/XAMPP/xamppfiles/bin:$PATH

After editing is complete, call source ~/.bash_prpfile to apply the changes.

Debug:

Debug log in each view

Debug sql query:

Eloquent ORM in Laravel

  • Each table in the database corresponds to a model.
  • Model allows query, insert, update table in db.

The command to create a model:

Facade:

What?

  • Facade provides a static interface for classes available in the service container.
  • Larvel provides most complete facades for working with Laravel features.

eg:

When to use?

  • There are many benefits such as: short, easy to remember to use all the features of Laravel without having to remember all the classes with very long names.
  • Use for easy creation in testing. (interface type)

Facade & Dependence Injection:

  • facades use dynamic methods to proxy method calls to objects to resolve from the service container, we actually can test facades just as we would test an injected class instance.

ex:

Write the test to verify Cache :: get:

Facade work ntn?

  • The Facade base class makes use of the __callStatic() magic-method to defer calls from your facade to an object resolved from the container
  • eg:

Blade Templates in Laravel:

What?

Blade is the simple yet powerful templating tool provided with Laravel. Unlike other php engine templates, Blade does not restrict the use of PHP code in the view. Blade snippets are compiled into plain PHP code and cached until it is changed. Blade view uses: .blade.php located in the resources/views directory

Template Inheritance:

Create a layout

2 Important purposes while using blade: inheriting template & sections. See eg:

In another template will declare a section content , the content will be drawn immediately yield

section : define a content yield : used to display the content of the section.

Expand for 1 layout

When creating a child view, use Blade @extends to specify the layout that the child view will inherit. eg:

@parent: to replace the content in the parent view.

Components & Slots

Create a component to display in {{$ slot}}

multiple slots for a component

Define component

Note Blade:

{{ }} : Blade sends data through PHP via a function: htmlspecialchars.

{!! $name !!} : Sent without data escaped.

@if @elseif .. condition



Include sub-view:

Render View for Collections:
Share the news now

Source : Viblo