Laravel quiz questions

Laravel interview questions

  • 1.

    Look at the code snippet. In what file would you register an observer like this?

    User::observe(UserObserver::class);

     

    1. AppServiceProvider 

    2. AuthServiceProvider

    3. RouteServiceProvider

    4. Kernel.php

    Answer
  • 2.

    php artisan key:generate Typically, it generates a string of what length?

    1. 32 characters

    2. 16 characters

    3. 6 characters

    4. random length 

    Answer
  • 3.

    Look at the code snippet. Method hasMany() has a second parameter which is not passed here. What field would be used in this case for relationship, if parameter isn't specified?
     

    class Post extends Model
    {
        public function comments()
        {
            return $this->hasMany('App\Comment');
        }
    }

     

    1. post_id 

    2. comment_id 
       

    3. id

    4. NULL

    Answer
  • 4.

    This helper function generates a random string of the specified length: str_XXXXXX($length)

    1. str_random

    2. str_rand

    3. str_string

    4. str_generate

    Answer
  • 5.

    When using the daily log mode (files like laravel-2016-12-09.log), Laravel by default will only retain X days of log files by default. X = ?

    1. 5 days

    2. 30 days

    3. 1 day

    4. unlimited

    Answer
  • 6.

    Where can you find a default timezone set?

    1. config/app.php

    2. config/timezone.php

    3. config/carbon.php

    4. config/env.php 

    Answer
  • 7.

    If you want your users to login with "username" field instead of default "email", what property you need to add to AuthController.php class? What's behind xxxxxxx?

    protected $xxxxxxx = 'username';

     

    1. username

    2. login

    3. user_id 

    4. credentials

    Answer
  • 8.

    Look at the code snippet. What will this function do?
     

    info('Some helpful information!');

     

    1. Write text to the log

    2. Show text in the browser on top

    3. Send an email to administrator 

    4. It works only in command line mode and will show the text there

    Answer
  • 9.

    How to run database migrations and call "db:seed" command immediately afterwards?

    1. artisan migrate --seed

    2. artisan migrate:seed

    3. artisan migrate seed 

    4. artisan db:migrate_seed

    Answer
  • 10.

    In Laravel 5.3 routes folder, there are three files: web.php, api.php and....?

    1. console.php 

    2. artisan.php
       

    3. routes.php

    4. http.php
       

    Answer
  • 11.

    Laravel uses syntax ::class quite heavily. When it was introduced - in which PHP version?
     

    1. 5.5 

    2. 5.4
       

    3. 5.3
       

    4. 7.0
       

    Answer
  • 12.

    Look at the code snippet. What SQL query clause would it produce?
     

    $q->where(function ($query) {
        $query->where('gender', 'Male')
            ->where('age', '>=', 18);
    })->orWhere(function($query) {
        $query->where('gender', 'Female')
            ->where('age', '>=', 65);	
    })

     

    1. ... WHERE (gender = 'Male' and age >= 18) or (gender = 'Female' and age >= 65)

    2. ... WHERE (gender = 'Male' or age >= 18) and (gender = 'Female' or age >= 65)

    3. ... WHERE gender = 'Male' and age >= 18 or gender = 'Female' and age >= 65

    4. ... WHERE gender = 'Male' and age >= 18 and gender = 'Female' and age >= 65 

    Answer
  • 13.

    To enable maintenance mode, simply execute this Artisan command:

    1. artisan down

    2. artisan maintenance

    3. artisan reset 

    4. artisan stop

    Answer
  • 14.

    There is an option for migrations called "pretend". What does it do?

    artisan migrate --pretend

     

    1. Shows SQL queries for migrations

    2. Dumps current DB structure into migrations

    3. Checks if migrations syntax is correct

    4. Tries to run migrations and sends the result to Log file 
       

    Answer
  • 15.

    With default Laravel settings and domain http://domain.com, what would be the result of this function?

    $filename = asset('css/style.css');

     

    1. http://domain.com/css/style.css

    2. http://domain.com/public/css/style.css

    3. http://domain.com/assets/css/style.css 

    4. http://domain.com/resources/assets/css/style.css

    Answer
  • 16.

    Look at the code snippet. Let's say you have a 'photo' file and it's processed by this line. What would be the filename saved?

    $request->photo->store('images');

     

    1. Automatically generated using the MD5 hash

    2. photo.jpg

    3. photo.xxx where xxx extension is specified in config 

    4. images.png

    Answer
  • 17.

    The ONLY Laravel helper method which name consists of only ONE letter?

    1. e()

    2. d()

    3. n()

    4. x() 

    Answer
  • 18.

    Look at the code snippet - you want to override default updated_at field. What should be the contents of array parameter for this to work? What's behind XXXXXX?

    $product = Product::find($id);
    $product->updated_at = '2015-01-01 10:00:00';
    $product->save([XXXXXX]);

     

    1. 'timestamps' => false

    2. 'updated_at' => false
       

    3. 'update' => false 

    4. 'updated_at' => NULL

    Answer
  • 19.

    See code snippet. What would $result contain?
     

    $result = Product::whereNull('category_id')->update(['category_id' => 2]);
    

     

    1. Number of affected rows

    2. TRUE or FALSE
       

    3. 1 or 0
       

    4. Update function doesn't return anything
       

    Answer
  • 20.

    If you see an error "No supported encrypter found. The cipher and / or key length are invalid." - what command you need to launch?

    1. artisan key:generate

    2. composer install 
       

    3. composer update

    4. artisan migrate

    Answer

© 2017 QuizBucket.org