0
0
Laravelframework~10 mins

Session basics in Laravel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to store a value in the session.

Laravel
<?php

use Illuminate\Support\Facades\Session;

Session::[1]('key', 'value');
Drag options to blanks, or click blank then click option'
Aput
Bget
Cforget
Dhas
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'put' to store data.
Using 'forget' which deletes data.
2fill in blank
medium

Complete the code to retrieve a value from the session.

Laravel
<?php

use Illuminate\Support\Facades\Session;

$value = Session::[1]('key');
Drag options to blanks, or click blank then click option'
Aget
Bput
Cforget
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'put' which stores data instead of retrieving.
Using 'forget' which removes data.
3fill in blank
hard

Fix the error in the code to remove a session value.

Laravel
<?php

use Illuminate\Support\Facades\Session;

Session::[1]('key');
Drag options to blanks, or click blank then click option'
Aput
Bget
Cforget
Dhas
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' which only reads data.
Using 'put' which writes data.
4fill in blank
hard

Fill both blanks to check if a session key exists and then retrieve it.

Laravel
<?php

use Illuminate\Support\Facades\Session;

if (Session::[1]('key')) {
    $value = Session::[2]('key');
}
Drag options to blanks, or click blank then click option'
Ahas
Bput
Cget
Dforget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'put' instead of 'get' to retrieve data.
Using 'forget' which deletes data.
5fill in blank
hard

Fill all three blanks to flash a message to the session and then retrieve it.

Laravel
<?php

use Illuminate\Support\Facades\Session;

Session::[1]('status', 'Profile updated!');

$message = Session::[2]('status');

Session::[3]('status');
Drag options to blanks, or click blank then click option'
Aput
Bget
Cforget
Dflash
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'put' instead of 'flash' for temporary messages.
Not removing the message after retrieving.