9 Questions
In Laravel, what directive is used to inherit a section from a parent view?
@parent
When passing data to views in Laravel, which method is used to pass an associative array?
->with()
What will be displayed in the 'employee.blade.php' view from the given code: {{$name}} {{$age}} {{$department}}?
Napoleon 26 IT Department
In Laravel Blade, what is the correct way to access a variable that is not in an array?
{{ $name }}
What data will be passed to the 'students.blade.php' view from the given code: ->with('students', $students) ->with('grade', $grade) ->with('age', $age)?
$students, $grade, $age
What value of 'grade' will be available in the 'students.blade.php' view?
70
Which directive is used to include the content of a blade view within another blade view?
@include
What is the purpose of the Blade directive '@extend' in Laravel?
To extend the layout of a view
Which method is used to pass data to a blade view in Laravel within a route callback function?
->with()
Study Notes
Conditional Statements
-
@if
directive is used for conditional statements, e.g.,@if ($grade==75)
-
@elseif
is used for alternative conditions, e.g.,@elseif ($grade>75)
-
@else
is used for the default condition, e.g.,@else You Failed!
-
@endif
is used to end the conditional statement
Switch Case
-
@switch
directive is used for switch case statements, e.g.,@switch ($grade)
-
@case
is used to specify a case, e.g.,@case(80)
-
@break
is used to break out of the switch case -
@default
is used for the default case, e.g.,@default Your grade is not known!
-
@endswitch
is used to end the switch case statement
Loops
-
@for
directive is used for for loops, e.g.,@for ($i = 0; $i < 10)
-
@endfor
is used to end the for loop -
@foreach
directive is used for foreach loops, e.g.,@foreach ($students as $student)
-
@endforeach
is used to end the foreach loop
Loop Variables
-
$loop
variable provides information about the current loop iteration -
$loop->index
returns the index of the current loop iteration (starts at 0) -
$loop->iteration
returns the current loop iteration (starts at 1) -
$loop->remaining
returns the iteration remaining in the loop -
$loop->count
returns the total number of items in the array being iterated -
$loop->first
returns whether this is the first iteration through the loop -
$loop->last
returns whether this is the last iteration through the loop -
$loop->depth
returns the nesting level of the current loop -
$loop->parent
returns the parent's loop variable when in a nested loop
Check if Set and Check if Empty
-
@isset
directive is used to check if a variable is set, e.g.,@isset ($students)
-
@endisset
is used to end the isset statement -
@empty
directive is used to check if a variable is empty, e.g.,@empty ($students)
-
@endempty
is used to end the empty statement
Test your knowledge on conditional statements and switch case examples in Laravel Blade directives. The quiz covers scenarios like grading based on conditions and demonstrating switch cases.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free