Laravel quiz questions

Laravel interview questions

  • 1.

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

    After running artisan make:auth - what new controller will be generated? 

    1. AuthController.php

    2. RegisterController.php
       

    3. HomeController.php

    4. LoginController.php
       

    Answer
  • 3.

    Look at the code snippet. If that middleware fails, what HTTP code would be returned?
     

    Route::put('/post/{post}', function (Post $post) {
        // The current user may update the post...
    })->middleware('can:update,post');

     

    1. 401

    2. 403 

    3. 500 

    4. 200
       

    Answer
  • 4.

    What are the methods used in database migrations classes?

    1. execute() and rollback()

    2. up() and down()

    3. forward() and back()

    4. run() and history()
       

    Answer
  • 5.

    This command will roll back all of your migrations and then execute the migrate command. This command effectively re-creates your entire database.

    1. migrate:refresh

    2. migrate:reset

    3. migrate:rollback 

    4. migrate --seed

    Answer
  • 6.

    Look at the snippet below - command generates the test. What does the class extend? What's behind XXXXXX?

    php artisan make:test UserTest
    class UserTest extends XXXXXX
    {
    // ...

     

    1. TestCase

    2. Test

    3. UnitTest

    4. TestClass

    Answer
  • 7.

    Look at the code snippet. What relationship will it actually make?
     

    class Comment extends Model
    {
        /**
         * Get the post that owns the comment.
         */
        public function post()
        {
            return $this->belongsTo('App\Post', 'post_id', 'post_id');
        }
    }

     

    1. comments.post_id = posts.post_id

    2. comments.post_id = posts.id

    3. comments.id = posts.id 

    4. comments.comments_post_id = posts.id

    Answer
  • 8.

    What is Blade syntax to show a variable, avoiding error if the variable is not defined? (and then showing empty string)

    1. {{ $var or '' }}

    2. {{ $var | '' }}

    3. {{ $var('') }}

    4. {!! $var !!} 

    Answer
  • 9.

    In Laravel 5, all controllers by default should extend Controller. If you want to edit or add some code to that "main" controller, where is it located?

    1. In app/Http/Controllers folder 

    2. In resources/controllers folder

    3. In vendor folder and you cannot edit it 

    4. In bootstrap/controllers folder

    Answer
  • 10.

    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. 30 days  

    2. unlimited  

    3. 1 day  
       

    4. 5 days

    Answer
  • 11.

    In default Laravel Auth, when user fills in email in "Forgot password", where the generated token is stored?

    1. In database table "password_resets"

    2. In database table "users"

    3. In storage/passwords.php file

    4. In session of the user

    Answer
  • 12.

    See snippet below - user is redirected with flashed data. How that 'status' variable can be used after redirect?
     

    return redirect('dashboard')->with('status', 'Profile updated!');

     

    1. session('status')

    2. $request->status

    3. Input::get('status')

    4. Just $status

    Answer
  • 13.

    Look at code snippet. What would this touch() function do?
     

    $user = User::find(1);
    $user->touch();

     

    1. Update updated_at to current time 

    2. Check if entry exists

    3. Check if auto_increment value is correct

    4. Update user's password
       

    Answer
  • 14.

    Look at the code snippet. This was introduced in which Laravel version?
     

    if (Gate::forUser($user)->allows('update-post', $post)) {
        //
    }
    if ($request->user()->can('update-post', $post)) {
        // ... Update post
    }
    @can('update-post', $post)
        Edit Post
    @endcan

     

    1. 5.1.11

    2. 5.0.11

    3. 5.2.11

    4. 4.2.11
       

    Answer
  • 15.

    After running "artisan down", your project will show maintenance page. What HTTP Status Code it would return?

    1. 503

    2. 200

    3. 404 

    4. 500

    Answer
  • 16.

    What is the minimum PHP version required to install Laravel 5.3?

    1. 5.6.4 

    2. 5.5.1

    3. 5.4.13

    4. 7.0.1

    Answer
  • 17.

    See code snippet. What's the word behind XXXXXXXX?

    @XXXXXXXX ($users as $user)
        This is user {{ $user->id }}
    @empty
        No users found.
    @endXXXXXXXX

     

    1. forelse

    2. foreach

    3. if 

    4. while

    Answer
  • 18.

    You want to get the last (newest) registered user. What is behind XXXXXX?

    $user = DB::table('users')->XXXXXX()->first();

     

    1. latest

    2. newest

    3. last
       

    4. take 

    Answer
  • 19.

    Look at the code snippet - in database migrations rollback, you usually run something like this. What is another function that additionally checks if that table actually exists?
     

    Schema::drop('users');

     

    1. dropIfExists 

    2. softDrop 

    3. checkDrop

    4. dropDrop

    Answer
  • 20.

    Look at the code snippet of dropping a foreign key. What if you don't know the exact name of that key? Is it possible to drop the key only by field name? How would it look?
     

    $table->dropForeign('posts_user_id_foreign');

     

    1. $table->dropForeign(['user_id']); 

    2. $table->dropForeign('user_id');

    3. $table->dropForeign('field', 'user_id'); 

    4. It is impossible

    Answer

© 2017 QuizBucket.org