Question 1 of 50
In Laravel, which method on the Illuminate\Http\Request instance is used to retrieve all input data as an array?
A
$request->input()
B
$request->obtain()
C
$request->get()
D
$request->all()
Not quite. Try another option.
Answer: $request->all()
The $request->all() method returns all of the incoming request's input data as an array.
Question 2 of 50
How can you retrieve a specific input value named 'username' from the request, returning 'Guest' if the value is not present?
A
$request->get('username', 'Guest')
B
$request->retrieve('username', 'Guest')
C
$request->input('username', 'Guest')
D
$request->username('Guest')
Not quite. Try another option.
Answer: $request->input('username', 'Guest')
The input method accepts a second argument which serves as the default value if the requested input key is not present.
Question 3 of 50
Which method is used to determine if a value is present on the request?
A
$request->isset('key')
B
$request->present('key')
C
$request->exists('key')
D
$request->has('key')
Not quite. Try another option.
Answer: $request->has('key')
The has method returns true if the value is present on the request. The whenHas method can also be used to execute a closure if the value exists.
Question 4 of 50
When handling a boolean input like a checkbox that might return "true", "on", or "1", which method retrieves it as a boolean true or false?
A
$request->boolean('key')
B
$request->isTrue('key')
C
$request->check('key')
D
$request->bool('key')
Not quite. Try another option.
Answer: $request->boolean('key')
The boolean method returns true for 1, "1", true, "true", "on", and "yes". All other values return false.
Question 5 of 50
Which request method allows you to retrieve a subset of the input data?
A
$request->only(['key1', 'key2'])
B
$request->limit(['key1', 'key2'])
C
$request->include(['key1', 'key2'])
D
$request->some(['key1', 'key2'])
Not quite. Try another option.
Answer: $request->only(['key1', 'key2'])
The only method (and conversely the except method) allows you to retrieve a specific subset of the input data.
Question 6 of 50
Which HTML attribute is mandatory for a form to upload files successfully?
A
enctype="multipart/form-data"
B
method="get"
C
action="upload"
D
type="file-upload"
Not quite. Try another option.
Answer: enctype="multipart/form-data"
The form must use the POST method and set the enctype attribute to multipart/form-data for files to be transmitted to the server.
Question 7 of 50
How do you verify that an uploaded file was successfully uploaded and is valid?
A
$request->file('photo')->isOK()
B
$request->file('photo')->exists()
C
$request->file('photo')->isValid()
D
$request->file('photo')->verified()
Not quite. Try another option.
Answer: $request->file('photo')->isValid()
The isValid method verifies that there were no problems uploading the file.
Question 8 of 50
Which method is typically used to store an uploaded file to a configured disk?
A
upload()
B
save()
C
store()
D
move()
Not quite. Try another option.
Answer: store()
The store method will generate a unique ID for the file and store it on the specified disk (e.g., local, s3).
Question 9 of 50
How can you retrieve the original file extension of an uploaded file?
A
$file->ext()
B
$file->extension()
C
$file->getOriginalExtension()
D
$file->getClientOriginalExtension()
Not quite. Try another option.
Answer: $file->getClientOriginalExtension()
The getClientOriginalExtension method returns the extension of the file as determined by the client.
Question 10 of 50
Which method generates a SHA-256 hash of the uploaded file's contents to use as a filename?
A
$file->getHash()
B
$file->nameHash()
C
$file->hashName()
D
$file->generateName()
Not quite. Try another option.
Answer: $file->hashName()
The hashName method generates a unique filename based on the file content's hash.
Question 11 of 50
In Laravel, how does the framework handle input from the previous request to repopulate forms after validation errors?
A
It saves input to the database.
B
It appends input to the URL.
C
It uses caching.
D
It flashes input to the session.
Not quite. Try another option.
Answer: It flashes input to the session.
Laravel allows you to keep input from one request during the next request using the flash method, which is commonly used for validation errors.
Question 12 of 50
Which global helper function is used in Blade templates to retrieve old input?
A
input()
B
old()
C
previous()
D
last()
Not quite. Try another option.
Answer: old()
The old helper retrieves the flashed input data from the previous request. Example: <input name="username" value="{{ old('username') }}">.
Question 13 of 50
When redirecting, how do you chain a method to flash the current input to the session?
A
->saveInput()
B
->withInput()
C
->keepInput()
D
->flashInput()
Not quite. Try another option.
Answer: ->withInput()
The withInput() method is chained onto a redirect instance to flash the current request's input data to the session.
Question 14 of 50
By default, Laravel cookies are encrypted and signed. What does this prevent?
A
It prevents the server from reading the cookie.
B
It prevents the cookie from expiring.
C
It prevents the client from modifying the cookie.
D
It prevents the client from viewing the cookie.
Not quite. Try another option.
Answer: It prevents the client from modifying the cookie.
Encryption and signing ensure that if the client modifies the cookie, the signature will become invalid, and Laravel will discard it.
Question 15 of 50
How do you retrieve a cookie value from the incoming request?
A
$request->getCookie('name')
B
$request->cookie('name')
C
$request->cookies['name']
D
Cookie::get('name')
Not quite. Try another option.
Answer: $request->cookie('name')
The $request->cookie('name') method is the standard way to retrieve a cookie value from the request instance.
Question 16 of 50
Which method allows you to attach a cookie to a response instance?
A
cookie)
B
cookie)
C
cookie)
D
cookie)
Not quite. Try another option.
Answer: cookie)
The withCookie method attaches a cookie to the outgoing Illuminate\Http\Response instance.
Question 17 of 50
What is the helper function to generate a cookie instance?
A
make_cookie()
B
generate_cookie()
C
create_cookie()
D
cookie()
Not quite. Try another option.
Answer: cookie()
The global cookie() helper function serves as a factory to create new cookie instances.
Question 18 of 50
Which Artisan command is used to create a new Mailable class?
A
php artisan generate:mail
B
php artisan new:mail
C
php artisan create:mail
D
php artisan make:mail
Not quite. Try another option.
Answer: php artisan make:mail
The make:mail command creates a new mailable class in the app/Mail directory.
Question 19 of 50
In a Mailable class, which method is used to configure the email content (e.g., view, subject)?
A
render()
B
build()
C
construct()
D
compose()
Not quite. Try another option.
Answer: build()
The build method in a Mailable class is where you verify the configuration of the email, such as the subject and the Blade view to render.
Question 20 of 50
Which method is used on the Mail facade to specify the recipient?
A
Mail::to()
B
Mail::sendTo()
C
Mail::for()
D
Mail::recipient()
Not quite. Try another option.
Answer: Mail::to()
The Mail::to($recipient) method specifies the address the email is being sent to.
Question 21 of 50
How do you attach a file to an email within the build method of a Mailable?
A
$this->file('/path/to/file')
B
$this->attach('/path/to/file')
C
$this->append('/path/to/file')
D
$this->addFile('/path/to/file')
Not quite. Try another option.
Answer: $this->attach('/path/to/file')
The attach method is used to add attachments to the email.
Question 22 of 50
To queue an email for background sending instead of sending it immediately, which method should be used?
A
queue()
B
defer()
C
later()
D
background()
Not quite. Try another option.
Answer: queue()
The queue method pushes the email task onto the application's queue to be processed in the background.
Question 23 of 50
Which directory stores the language files for Laravel Localization?
A
storage/lang
B
config/lang
C
app/lang
D
resources/lang
Not quite. Try another option.
Answer: resources/lang
Laravel stores localization files in the resources/lang directory.
Question 24 of 50
How do you retrieve a translation string for the key 'welcome' located in messages.php?
A
lang('messages.welcome')
B
trans('messages/welcome')
C
__('messages.welcome')
D
locate('messages.welcome')
Not quite. Try another option.
Answer: __('messages.welcome')
The __ helper function retrieves the translation line. The dot syntax refers to the file and the key.
Question 25 of 50
What is the Blade directive equivalent to <?php echo __('messages.welcome'); ?>?
A
@lang('messages.welcome')
B
@echo('messages.welcome')
C
@locate('messages.welcome')
D
@trans('messages.welcome')
Not quite. Try another option.
Answer: @lang('messages.welcome')
The @lang directive is used to echo translated strings in Blade templates.
Question 26 of 50
If a translation string contains a placeholder like Welcome, :name, how do you replace it?
A
__('messages.welcome', 'John')
B
__('messages.welcome', ['name' => 'John'])
C
__('messages.welcome', ['name' : 'John'])
D
__('messages.welcome')->with('John')
Not quite. Try another option.
Answer: __('messages.welcome', ['name' => 'John'])
You pass an array of replacements as the second argument to the __ function.
Question 27 of 50
Which method allows you to change the application's current locale at runtime?
A
Locale::set('fr')
B
App::setLocale('fr')
C
Lang::locale('fr')
D
Config::set('locale', 'fr')
Not quite. Try another option.
Answer: App::setLocale('fr')
The App::setLocale() method changes the active locale for the current request.
Question 28 of 50
Which function is used for pluralization of translation strings based on a count?
A
lang_choice()
B
trans_plural()
C
trans_choice()
D
__plural()
Not quite. Try another option.
Answer: trans_choice()
The trans_choice function retrieves a translation line with pluralization rules based on a given integer count.
Question 29 of 50
Where is the default application locale configured?
A
resources/lang/config.php
B
.env only
C
config/app.php
D
config/locale.php
Not quite. Try another option.
Answer: config/app.php
The default locale is defined in the locale key within the config/app.php configuration file.
Question 30 of 50
Which configuration file handles the session settings?
A
config/storage.php
B
config/app.php
C
config/session.php
D
config/cache.php
Not quite. Try another option.
Answer: config/session.php
Session configuration options are stored in config/session.php.
Question 31 of 50
How can you access session data using the global helper?
A
session()->get('key')
B
session('key')
C
Session::get('key')
D
All of the above
Not quite. Try another option.
Answer: All of the above
You can access session data via the session() helper with a key, the session() instance using get, or the Session facade. All are valid methods.
Question 32 of 50
What is the syntax to store data in the session using the helper function?
A
session('key', 'value')
B
session(['key' => 'value'])
C
session()->put('key', 'value')
D
Both B and C
Not quite. Try another option.
Answer: Both B and C
You can store data by passing an array of key/value pairs to the session() helper or by using the put method on the session instance.
Question 33 of 50
Which method is used to push a new value onto a session array?
A
push()
B
append()
C
put()
D
add()
Not quite. Try another option.
Answer: push()
The push method is used to push a new value onto a session value that is an array.
Question 34 of 50
How do you retrieve an item from the session and delete it in a single statement?
A
retrieve()
B
grab()
C
pop()
D
pull()
Not quite. Try another option.
Answer: pull()
The pull method retrieves an item from the session and immediately removes it.
Question 35 of 50
Which method checks if a key exists in the session, returning true even if the value is null?
A
exists()
B
contains()
C
present()
D
has()
Not quite. Try another option.
Answer: exists()
The exists method checks if a key is present in the session, whereas has checks if it is present and not null.
Question 36 of 50
How do you remove a specific piece of data from the session?
A
forget()
B
remove()
C
drop()
D
delete()
Not quite. Try another option.
Answer: forget()
The forget method removes a specific key or array of keys from the session.
Question 37 of 50
Which method removes all data from the session?
A
wipe()
B
flush()
C
destroy()
D
clean()
Not quite. Try another option.
Answer: flush()
The flush method removes all data from the session.
Question 38 of 50
To prevent session fixation attacks, which method should be called typically during authentication?
A
$request->session()->secure()
B
$request->session()->regenerate()
C
$request->session()->fix()
D
$request->session()->renew()
Not quite. Try another option.
Answer: $request->session()->regenerate()
The regenerate method regenerates the session ID, which helps prevent session fixation attacks.
Question 39 of 50
How do you store items in the session only for the next request?
A
next()
B
temp()
C
flash()
D
short()
Not quite. Try another option.
Answer: flash()
The flash method stores data in the session for the next request only. It is automatically removed afterwards.
Question 40 of 50
If you need to keep flashed data for one more additional request, which method do you use?
A
reflash()
B
keep()
C
extend()
D
persist()
Not quite. Try another option.
Answer: reflash()
The reflash method keeps all flashed data for an additional request. keep() can be used to keep specific keys.
Question 41 of 50
In the context of MVC and URL generation, what function is used to generate a URL to a named route?
A
link()
B
route()
C
url()
D
path()
Not quite. Try another option.
Answer: route()
The route() helper function generates a URL for a given named route.
Question 42 of 50
If a route is defined as Route::get('/post/{id}', ...)->name('post.show'), how do you generate the URL for ID 5?
A
route('post.show', ['id' => 5])
B
Both A and C
C
route('post.show', 5)
D
url('post.show', 5)
Not quite. Try another option.
Answer: Both A and C
You can pass the parameter directly or as an array. route('post.show', 5) and route('post.show', ['id' => 5]) both work.
Question 43 of 50
Which Request method gives you the full URL including the query string?
A
$request->fullUrl()
B
$request->uri()
C
$request->url()
D
$request->path()
Not quite. Try another option.
Answer: $request->fullUrl()
The fullUrl() method returns the full URL including the query string, whereas url() returns it without the query string.
Question 44 of 50
How can you access the query string parameters as an array?
A
$request->params()
B
$request->getParams()
C
$request->queryString()
D
$request->query()
Not quite. Try another option.
Answer: $request->query()
The query method retrieves the query string arguments from the request.
Question 45 of 50
When storing session data, which driver stores sessions in a file within storage/framework/sessions?
A
array
B
file
C
cookie
D
database
Not quite. Try another option.
Answer: file
The file session driver stores session data in files located in storage/framework/sessions.
Question 46 of 50
Using the database session driver requires what preliminary step?
A
Installing Redis
B
Configuring AWS credentials
C
Setting up Memcached
D
Creating a session table
Not quite. Try another option.
Answer: Creating a session table
To use the database driver, you need a table to contain the session items (usually created via php artisan session:table).
Question 47 of 50
In Localization, what is the fallback locale?
A
The locale used if the selected language line does not exist in the active locale.
B
The locale used if the user is not logged in.
C
The locale determined by the browser headers.
D
The locale used for admin users.
Not quite. Try another option.
Answer: The locale used if the selected language line does not exist in the active locale.
The fallback locale (configured in config/app.php) is used when a translation key cannot be found in the current active locale.
Question 48 of 50
If you want to increment a value in the session, which logic is most appropriate?
A
$val = session('key') + 1; session(['key' => $val]);
B
session()->plus('key')
C
session()->add('key', 1)
D
session()->increment('key')
Not quite. Try another option.
Answer: $val = session('key') + 1; session(['key' => $val]);
Sessions do not have a native increment method like the Cache facade. You must retrieve, calculate, and put the value back.
Question 49 of 50
What is the primary difference between $request->input() and $request->query()?
A
input() retrieves from payload (POST) and query string; query() retrieves only from query string.
B
query() is deprecated.
C
input() is for files; query() is for text.
D
There is no difference.
Not quite. Try another option.
Answer: input() retrieves from payload (POST) and query string; query() retrieves only from query string.
$request->input() is a general accessor for GET and POST data. $request->query() specifically targets parameters in the URL query string.
Question 50 of 50
If $x is a Request instance, what does $x->collect() return?
A
An array of inputs.
B
A JSON string of inputs.
C
A Laravel Collection instance of the inputs.
D
A boolean validation result.
Not quite. Try another option.
Answer: A Laravel Collection instance of the inputs.
The collect() method retrieves all of the incoming request's input data as a Illuminate\Support\Collection.