Unit 4 - Practice Quiz

INT221 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 In Laravel, which method on the Illuminate\Http\Request instance is used to retrieve all input data as an array?

A. $request->get()
B. $request->all()
C. $request->input()
D. $request->obtain()

2 How can you retrieve a specific input value named 'username' from the request, returning 'Guest' if the value is not present?

A. $request->input('username', 'Guest')
B. $request->get('username', 'Guest')
C. $request->username('Guest')
D. $request->retrieve('username', 'Guest')

3 Which method is used to determine if a value is present on the request?

A. $request->exists('key')
B. $request->has('key')
C. $request->isset('key')
D. $request->present('key')

4 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->bool('key')
B. $request->isTrue('key')
C. $request->boolean('key')
D. $request->check('key')

5 Which request method allows you to retrieve a subset of the input data?

A. $request->some(['key1', 'key2'])
B. $request->only(['key1', 'key2'])
C. $request->limit(['key1', 'key2'])
D. $request->include(['key1', 'key2'])

6 Which HTML attribute is mandatory for a form to upload files successfully?

A. enctype="multipart/form-data"
B. type="file-upload"
C. method="get"
D. action="upload"

7 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()

8 Which method is typically used to store an uploaded file to a configured disk?

A. save()
B. store()
C. upload()
D. move()

9 How can you retrieve the original file extension of an uploaded file?

A. $file->extension()
B. $file->getClientOriginalExtension()
C. $file->getOriginalExtension()
D. $file->ext()

10 Which method generates a SHA-256 hash of the uploaded file's contents to use as a filename?

A. $file->hashName()
B. $file->nameHash()
C. $file->getHash()
D. $file->generateName()

11 In Laravel, how does the framework handle input from the previous request to repopulate forms after validation errors?

A. It uses caching.
B. It flashes input to the session.
C. It saves input to the database.
D. It appends input to the URL.

12 Which global helper function is used in Blade templates to retrieve old input?

A. previous()
B. old()
C. last()
D. input()

13 When redirecting, how do you chain a method to flash the current input to the session?

A. ->flashInput()
B. ->withInput()
C. ->saveInput()
D. ->keepInput()

14 By default, Laravel cookies are encrypted and signed. What does this prevent?

A. It prevents the client from viewing the cookie.
B. It prevents the client from modifying the cookie.
C. It prevents the cookie from expiring.
D. It prevents the server from reading the cookie.

15 How do you retrieve a cookie value from the incoming request?

A. $request->getCookie('name')
B. $request->cookie('name')
C. Cookie::get('name')
D. $request->cookies['name']

16 Which method allows you to attach a cookie to a response instance?

A. cookie)
B. cookie)
C. cookie)
D. cookie)

17 What is the helper function to generate a cookie instance?

A. make_cookie()
B. cookie()
C. generate_cookie()
D. create_cookie()

18 Which Artisan command is used to create a new Mailable class?

A. php artisan create:mail
B. php artisan make:mail
C. php artisan generate:mail
D. php artisan new:mail

19 In a Mailable class, which method is used to configure the email content (e.g., view, subject)?

A. construct()
B. build()
C. compose()
D. render()

20 Which method is used on the Mail facade to specify the recipient?

A. Mail::sendTo()
B. Mail::recipient()
C. Mail::to()
D. Mail::for()

21 How do you attach a file to an email within the build method of a Mailable?

A. $this->addFile('/path/to/file')
B. $this->attach('/path/to/file')
C. $this->file('/path/to/file')
D. $this->append('/path/to/file')

22 To queue an email for background sending instead of sending it immediately, which method should be used?

A. later()
B. background()
C. queue()
D. defer()

23 Which directory stores the language files for Laravel Localization?

A. resources/lang
B. app/lang
C. config/lang
D. storage/lang

24 How do you retrieve a translation string for the key 'welcome' located in messages.php?

A. lang('messages.welcome')
B. __('messages.welcome')
C. trans('messages/welcome')
D. locate('messages.welcome')

25 What is the Blade directive equivalent to <?php echo __('messages.welcome'); ?>?

A. @trans('messages.welcome')
B. @lang('messages.welcome')
C. @locate('messages.welcome')
D. @echo('messages.welcome')

26 If a translation string contains a placeholder like Welcome, :name, how do you replace it?

A. __('messages.welcome', ['name' => 'John'])
B. __('messages.welcome')->with('John')
C. __('messages.welcome', 'John')
D. __('messages.welcome', ['name' : 'John'])

27 Which method allows you to change the application's current locale at runtime?

A. Config::set('locale', 'fr')
B. App::setLocale('fr')
C. Lang::locale('fr')
D. Locale::set('fr')

28 Which function is used for pluralization of translation strings based on a count?

A. trans_plural()
B. trans_choice()
C. __plural()
D. lang_choice()

29 Where is the default application locale configured?

A. config/app.php
B. config/locale.php
C. .env only
D. resources/lang/config.php

30 Which configuration file handles the session settings?

A. config/session.php
B. config/app.php
C. config/cache.php
D. config/storage.php

31 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

32 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

33 Which method is used to push a new value onto a session array?

A. put()
B. push()
C. add()
D. append()

34 How do you retrieve an item from the session and delete it in a single statement?

A. retrieve()
B. pull()
C. pop()
D. grab()

35 Which method checks if a key exists in the session, returning true even if the value is null?

A. has()
B. exists()
C. present()
D. contains()

36 How do you remove a specific piece of data from the session?

A. delete()
B. remove()
C. forget()
D. drop()

37 Which method removes all data from the session?

A. destroy()
B. clean()
C. wipe()
D. flush()

38 To prevent session fixation attacks, which method should be called typically during authentication?

A. $request->session()->regenerate()
B. $request->session()->fix()
C. $request->session()->secure()
D. $request->session()->renew()

39 How do you store items in the session only for the next request?

A. next()
B. flash()
C. temp()
D. short()

40 If you need to keep flashed data for one more additional request, which method do you use?

A. keep()
B. reflash()
C. extend()
D. persist()

41 In the context of MVC and URL generation, what function is used to generate a URL to a named route?

A. url()
B. link()
C. route()
D. path()

42 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', 5)
B. url('post.show', 5)
C. route('post.show', ['id' => 5])
D. Both A and C

43 Which Request method gives you the full URL including the query string?

A. $request->url()
B. $request->fullUrl()
C. $request->path()
D. $request->uri()

44 How can you access the query string parameters as an array?

A. $request->query()
B. $request->params()
C. $request->queryString()
D. $request->getParams()

45 When storing session data, which driver stores sessions in a file within storage/framework/sessions?

A. cookie
B. file
C. database
D. array

46 Using the database session driver requires what preliminary step?

A. Installing Redis
B. Creating a session table
C. Setting up Memcached
D. Configuring AWS credentials

47 In Localization, what is the fallback locale?

A. The locale used if the user is not logged in.
B. The locale used if the selected language line does not exist in the active locale.
C. The locale determined by the browser headers.
D. The locale used for admin users.

48 If you want to increment a value in the session, which logic is most appropriate?

A. session()->increment('key')
B. val]);
C. session()->add('key', 1)
D. session()->plus('key')

49 What is the primary difference between request->query()?

A. input() retrieves from payload (POST) and query string; query() retrieves only from query string.
B. input() is for files; query() is for text.
C. query() is deprecated.
D. There is no difference.

50 If 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.