Laravel 10 Adalah

You can’t perform that action at this time.

themeselection/materio-bootstrap-html-laravel-admin-template-free

You can’t perform that action at this time.

You can’t perform that action at this time.

Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates. In fact, all Blade templates are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application. Blade template files use the .blade.php file extension and are typically stored in the resources/views directory.

Blade views may be returned from routes or controllers using the global view helper. Of course, as mentioned in the documentation on views, data may be passed to the Blade view using the view helper's second argument:

Route::get('/', function () {

return view('greeting', ['name' => 'Finn']);

Want to take your Blade templates to the next level and build dynamic interfaces with ease? Check out Laravel Livewire. Livewire allows you to write Blade components that are augmented with dynamic functionality that would typically only be possible via frontend frameworks like React or Vue, providing a great approach to building modern, reactive frontends without the complexities, client-side rendering, or build steps of many JavaScript frameworks.

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

Route::get('/', function () {

return view('welcome', ['name' => 'Samantha']);

You may display the contents of the name variable like so:

Blade's {{ }} echo statements are automatically sent through PHP's htmlspecialchars function to prevent XSS attacks.

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:

The current UNIX timestamp is {{ time() }}.

By default, Blade (and the Laravel e function) will double encode HTML entities. If you would like to disable double encoding, call the Blade::withoutDoubleEncoding method from the boot method of your AppServiceProvider:

namespace App\Providers;

use Illuminate\Support\Facades\Blade;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider

* Bootstrap any application services.

public function boot(): void

Blade::withoutDoubleEncoding();

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

Be very careful when echoing content that is supplied by users of your application. You should typically use the escaped, double curly brace syntax to prevent XSS attacks when displaying user supplied data.

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:

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

The @ symbol may also be used to escape Blade directives:

{{-- Blade template --}}

Sometimes you may pass an array to your view with the intention of rendering it as JSON in order to initialize a JavaScript variable. For example:

var app = ;

However, instead of manually calling json_encode, you may use the Illuminate\Support\Js::from method directive. The from method accepts the same arguments as PHP's json_encode function; however, it will ensure that the resulting JSON is properly escaped for inclusion within HTML quotes. The from method will return a string JSON.parse JavaScript statement that will convert the given object or array into a valid JavaScript object:

var app = {{ Illuminate\Support\Js::from($array) }};

The latest versions of the Laravel application skeleton include a Js facade, which provides convenient access to this functionality within your Blade templates:

var app = {{ Js::from($array) }};

You should only use the Js::from method to render existing variables as JSON. The Blade templating is based on regular expressions and attempts to pass a complex expression to the directive may cause unexpected failures.

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:

In addition to template inheritance and displaying data, Blade also provides convenient shortcuts for common PHP control structures, such as conditional statements and loops. These shortcuts provide a very clean, terse way of working with PHP control structures while also remaining familiar to their PHP counterparts.

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

@if (count($records) === 1)

@elseif (count($records) > 1)

I have multiple records!

I don't have any records!

For convenience, Blade also provides an @unless directive:

@unless (Auth::check())

You are not signed in.

In addition to the conditional directives already discussed, the @isset and @empty directives may be used as convenient shortcuts for their respective PHP functions:

// $records is defined and is not null...

// $records is "empty"...

The @auth and @guest directives may be used to quickly determine if the current user is authenticated or is a guest:

// The user is authenticated...

// The user is not authenticated...

If needed, you may specify the authentication guard that should be checked when using the @auth and @guest directives:

// The user is authenticated...

// The user is not authenticated...

You may check if the application is running in the production environment using the @production directive:

// Production specific content...

Or, you may determine if the application is running in a specific environment using the @env directive:

// The application is running in "staging"...

@env(['staging', 'production'])

// The application is running in "staging" or "production"...

You may determine if a template inheritance section has content using the @hasSection directive:

@hasSection('navigation')

You may use the sectionMissing directive to determine if a section does not have content:

@sectionMissing('navigation')

@include('default-navigation')

The @session directive may be used to determine if a session value exists. If the session value exists, the template contents within the @session and @endsession directives will be evaluated. Within the @session directive's contents, you may echo the $value variable to display the session value:

Switch statements can be constructed using the @switch, @case, @break, @default and @endswitch directives:

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

@for ($i = 0; $i < 10; $i++)

The current value is {{ $i }}

@foreach ($users as $user)

This is user {{ $user->id }}

@forelse ($users as $user)

  • {{ $user->name }}
  • I'm looping forever.

    While iterating through a foreach loop, you may use the loop variable to gain valuable information about the loop, such as whether you are in the first or last iteration through the loop.

    When using loops you may also skip the current iteration or end the loop using the @continue and @break directives:

    @foreach ($users as $user)

    @if ($user->type == 1)

  • {{ $user->name }}
  • @if ($user->number == 5)

    You may also include the continuation or break condition within the directive declaration:

    @foreach ($users as $user)

    @continue($user->type == 1)

  • {{ $user->name }}
  • @break($user->number == 5)

    While iterating through a foreach loop, a $loop variable will be available inside of your loop. This variable provides access to some useful bits of information such as the current loop index and whether this is the first or last iteration through the loop:

    @foreach ($users as $user)

    This is the first iteration.

    This is the last iteration.

    This is user {{ $user->id }}

    If you are in a nested loop, you may access the parent loop's $loop variable via the parent property:

    @foreach ($users as $user)

    @foreach ($user->posts as $post)

    @if ($loop->parent->first)

    This is the first iteration of the parent loop.

    The $loop variable also contains a variety of other useful properties:

    The @class directive conditionally compiles a CSS class string. The directive accepts an array of classes where the array key contains the class or classes you wish to add, while the value is a boolean expression. If the array element has a numeric key, it will always be included in the rendered class list:

    'font-bold' => $isActive,

    'text-gray-500' => ! $isActive,

    'bg-red' => $hasError,

    Likewise, the @style directive may be used to conditionally add inline CSS styles to an HTML element:

    'background-color: red',

    'font-weight: bold' => $isActive,

    For convenience, you may use the @checked directive to easily indicate if a given HTML checkbox input is "checked". This directive will echo checked if the provided condition evaluates to true:

    @checked(old('active', $user->active))

    Likewise, the @selected directive may be used to indicate if a given select option should be "selected":