Laravel quiz questions

Laravel interview questions

  • 1.

    Which database field is associated with "soft delete" functionality?

    1. deleted_at

    2. deleted

    3. delete 
       

    4. deleted_by
       

    Answer
  • 2.

    Look at the code snippet. The second relationship is inverse of the first one. What function is behind XXXXXX?

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


     

    1. belongsTo

    2. hasOne 

    3. hasManyThrough
       

    4. belongsToMany

    Answer
  • 3.

    You don’t want to use created_at and updated_at columns. What’s behind XXXXX?

    class Flight extends Model
    {
        public $XXXXX = false;
    }

     

    1. timestamps

    2. created_at

    3. times 

    4. dates

    Answer
  • 4.

    Look at the code snippet. What is a shorter way of writing the same thing?
     

    Product::where('category', 3)->get();
    

     

    1. Product::whereCategory(3)->get();

    2. Product::whereCategory3->get(); 
       

    3. Product::where_category(3)->get();
       

    4. Product::category(3)->get();
       

    Answer
  • 5.

    In Laravel 5.3 if you turn on maintenance mode, what would the default maintenance page say?
     

    1. Be right back

    2. Laravel 5 
       

    3. Page not found
       

    4. Maintenance mode
       

    Answer
  • 6.

    If you have validation rule 'confirmed', then you need to have two fields in the form with the same value. If one field has name 'password', another should be...?
     

    1. password_confirmation

    2. password2
       

    3. password_confirm
       

    4. password_confirmed 
       

    Answer
  • 7.

    Look at the code snippet. How that Query Scope would be called from the Controller?
     

    class Product extends Model
    {
    
        public function scopeExpensive($query)
        {
            return $query->where('price', '>', 100);
        }
    
    }

     

    1. Product::expensive()->get();

    2. Product::scopeExpensive()->get();

    3. Product::getExpensive()->get();
       

    4. Product::select('expensive')->get()
       

    Answer
  • 8.

    Look at the code snippet. There should be three tables in the database - "users", "roles" and...?

    class User extends Model
    {
        public function roles()
        {
            return $this->belongsToMany('App\Role');
        }
    }


     

    1. role_user 
       

    2. user_role 

    3. roles_users
       

    4. users_roles
       

    Answer
  • 9.

    What external package you need to run this pagination?
     

    $users = DB::table('users')->paginate(15);
    

     

    1. No package needed

    2. illuminate/html
       

    3. doctrine/dbal
       

    4. laravel/pagination
       

    Answer
  • 10.

    If you want to rename DB column with migration, what package you need for that?
     

    Schema::table('users', function ($table) {
        $table->renameColumn('from', 'to');
    });

     

    1. doctrine/dbal

    2. laravel/framework

    3. laravel/database

    4. no external package needed 

    Answer
  • 11.

    Let's say you have several languages folders like resources/lang/en and resources/lang/es. Where would the default language be set? In which file?
     

    1. config/app.php

    2. bootstrap/app.php

    3. app/Providers/AppServiceProvider.php 
       

    4. config/languages.php
       

    Answer
  • 12.

    While running database migrations, you can use extra parameter "artisan migrate --force". What this "force" will do?
     

    1. You won't be asked whether you really want to run migrations

    2. It will force migrations to run even if there's an error
       

    3. It will run only when environment is not "production"
       

    4. It will reset the whole database and run migrations from scratch

    Answer
  • 13.

    If you see MassAssignmentException after calling save() on your model, what property you probably need to fill in the model?
     

    1. $fillable 

    2. $table

    3. $timestamps
       

    4. $fields
       

    Answer
  • 14.

    In creating database schema, which of these columns doesn't exist in Laravel?
     

    1. $table->ipAddress('visitor');

    2. $table->macAddress('device');

    3. $table->dateTimeTz('created_at');

    4. $table->longString('description');

    Answer
  • 15.

    Out of the box, Laravel comes with two middleware groups that contains common middleware you may want to apply to your routes. What are those groups?

    1. web and api

    2. back and front
       

    3. admin and user

    4. auth and custom
       

    Answer
  • 16.

    Look at the code snippet - this is how the route is defined. How it should be called with a parameter?

    Route::get('user/{id}/profile', function ($id) {
        //
    })->name('profile');
    


     

    1. route('profile', ['id' => 1]); 

    2. route('profile', 'id', 1);
       

    3. route(['profile', 1]);
       

    4. route('profile', {1}); 
       

    Answer
  • 17.

    If you want to create your own 404 page, you need to create a resources/views/errors/404.blade.php file and...?
     

    1. Register it in AppServiceProvider 
       

    2. Point to it in .env file
       

    3. Assign it in the config/app.php file
       

    4. That's it, you don't need to do anything else 
       

    Answer
  • 18.

    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
  • 19.

    After running "make:policy" command, a new policy needs to be registered. In what file?

    1. AuthServiceProvider 

    2. RouteServiceProvider
       

    3. AppServiceProvider

    4. RouteServicesProvider

    Answer
  • 20.

    If we're using mail driver 'log', then the email texts instead of being sent will be ...
     

    1. Stored in laravel.log file 

    2. Stored in database table mail_log

    3. Not stored anywhere just return true or false

    4. Still sent but to the testing email address
       

    Answer

© 2017 QuizBucket.org