resources/views/ blade template
https://laravel.com/docs/8.x/blade#blade-directives
if not login
For convenience, Blade also provides an @unless
directive:
@unless (Auth::check()) You are not signed in.@endunless
In addition to the conditional directives already discussed, the @isset
and @empty
directives may be used as convenient shortcuts for their respective PHP functions:
@isset($records) // $records is defined and is not null...@endisset @empty($records) // $records is "empty"...@endempty
Authentication Directives
The @auth
and @guest
directives may be used to quickly determine if the current user is authenticated or is a guest:
@auth // The user is authenticated...@endauth @guest // The user is not authenticated...@endguest
If needed, you may specify the authentication guard that should be checked when using the @auth
and @guest
directives:
@auth('admin') // The user is authenticated...@endauth @guest('admin') // The user is not authenticated...@endguest
Environment Directives
You may check if the application is running in the production environment using the @production
directive:
@production // Production specific content...@endproduction
Or, you may determine if the application is running in a specific environment using the @env
directive:
@env('staging') // The application is running in "staging"...@endenv @env(['staging', 'production']) // The application is running in "staging" or "production"...@endenv
Section Directives
You may determine if a template inheritance section has content using the @hasSection
directive:
@hasSection('navigation') <div class="pull-right"> @yield('navigation') </div> <div class="clearfix"></div>@endif
You may use the sectionMissing
directive to determine if a section does not have content:
foreach,for,forelse,@while,switch
@If@elseif@else@endif
unless if count not there like that examples
loop variable
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) @if ($loop->first) This is the first iteration. @endif @if ($loop->last) This is the last iteration. @endif <p>This is user {{ $user->id }}</p>@endforeach
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. @endif @endforeach@endforeach
The $loop
variable also contains a variety of other useful properties:
Property | Description |
---|---|
$loop->index | The index of the current loop iteration (starts at 0). |
$loop->iteration | The current loop iteration (starts at 1). |
$loop->remaining | The iterations remaining in the loop. |
$loop->count | The total number of items in the array being iterated. |
$loop->first | Whether this is the first iteration through the loop. |
$loop->last | Whether this is the last iteration through the loop. |
$loop->even | Whether this is an even iteration through the loop. |
$loop->odd | Whether this is an odd iteration through the loop. |
$loop->depth | The nesting level of the current loop. |
$loop->parent | When in a nested loop, the parent's loop variable. |
laravel components
Which is the Blade's echo statement?
Marked Answer : {{ $name }}
Correct Answer : {{ $name }}
Which directives is used to determine if the current user is authenticated?
Marked Answer : "@auth"
Correct Answer : "@auth"
Which directive is used to determine if the application is running in the production environment?
Marked Answer : A and B both
Correct Answer : A and B both
Which directive is used to determine if a section does not have content?
Marked Answer : "sectionMissing"
Correct Answer : "sectionMissing"
Which property is used to gain current loop iteration?
Marked Answer : $loop->iteration
Correct Answer : $loop->iteration
No comments:
Post a Comment