Wednesday 1 April 2020

Laravel interview questions for 1 year experience

Laravel interview questions for 1 year experience

Question: How to make a helper file in laravel?
  1. Please create a app/helpers.php file in app folder.
  2. Add Following in in autoload variable.
    "files": [
        "app/helpers.php"
    ]
  3. Now update your composer.json
    composer update



Question: How to use mail() in laravel?
Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
    $m->from('from@example.com', 'Send Name');
    $m->to('receiver@example.com', 'Receiver Name')->subject('Your Reminder!');
});



Question: What is a REPL?
REPL is a type of interactive shell that takes in single user inputs, process them, and returns the result to the client. The full form of REPL is Read—Eval—Print—Loop


Question: How to use update query in Laravel?
Use Update function. for example
Blog::where(['id' => 10023])->update([
   'title' => 'Interview Questions',
   'content’ => 'Web Technology exerts notes'
]); 



Question: How to use multiple OR condition in Laravel Query?
Blog::where(['id' => 10023])->orWhere(['username’ => 'username12'])->update(['title' => 'Interview Questions',]);



Question: What are different type of where Clauses in Laravel?
  1. where()
  2. orWhere()
  3. whereBetween()
  4. orWhereBetween()
  5. whereNotBetween()
  6. orWhereNotBetween()
  7. wherein()
  8. whereNotIn()
  9. orWhereIn()
  10. orWhereNotIn()
  11. whereNull()
  12. whereNotNull()
  13. orWhereNull()
  14. orWhereNotNull()
  15. whereDate()
  16. whereMonth()
  17. whereDay()
  18. whereYear()
  19. whereTime()
  20. whereColumn()
  21. orWhereColumn()
  22. whereExists()



Question: What is updateOrInsert method? Give example?
updateOrInsert() method is used to update an existing record in the database if matching the condition or create if no matching record exists.
Blog::updateOrInsert([
   'title' => 'Interview Questions',   
]); 



Question: How to check table is exists or not in our database using Laravel?
if(Schema::hasTable('users')) {
    echo "Table Exists";
} else {
    echo "Table does not exists"
} 



Question: How to check column is exists or not in a table using Laravel?
if(Schema::hasColumn('users', 'title')) ; //check whether admin table has username column
{
   echo "Column Exists in table";
}else{
    echo "Column does not Exists in table";
}



Question: What are the difference between insert() and insertGetId() in laravel?
Inserts(): This method is used for insert records into the database table.
insertGetId(): This method is used for insert records into the database table and return the autoincrement-id.


Question: What is lumen?
Lumen is a PHP framework which is a faster, smaller and leaner version of a full web application framework.


Question: What is the full form of ORM in Laravel?
Object Relational Mapping.


Question: How to get current route name and method name?
request()->route()->getName(); //Return route name
request()->route()->getActionMethod();//Return method name



Question: How to check Ajax request in Laravel?
You can use the following syntax to check ajax request in laravel.
if ($request->ajax()) {
     echo "This is ajax requrest";
}



Question: What do you mean by bundles? In Laravel, bundles are referred to as packages.
These packages are used to increase the functionality of Laravel.
A package can have views, configuration, migrations, routes, and tasks.


Question: Name databases supported by Laravel.

  1. PostgreSQL
  2. SQL Server
  3. SQLite
  4. MySQL



Monday 30 March 2020

Laravel Interview Questions and answers for Fresher

Laravel Interview Questions and answers for Fresher

Question: What are the new features of Laravel 7?
Laravel 7.0 is incorporated features such as Better routing speed, Laravel Airlock, Custom Eloquent casts, Fluent string operations, CORS support, and many more features like below.
  1. Custom Eloquent Casts
  2. Route Caching Speed Improvements
  3. HTTP Client
  4. Query Time Casts
  5. Blade Component Tags & Improvements
  6. Laravel Airlock
  7. CORS Support
  8. Fluent string operations
  9. Multiple Mail Drivers
  10. New Artisan Commands etc


Question: What is the use of dd() in Laravel?
It is a helper function which is used to dump a variable's contents to the browser.
dd($arrayData);



Question: How to make a helper file in laravel?
  1. Please create a app/helpers.php file in app folder.
  2. Add Following in in autoload variable.
    "files": [
        "app/helpers.php"
    ]
  3. Now update your composer.json
    composer update


Question: What is PHP artisan in laravel? Name some common artisan commands?
Artisan is a type of the "command line interface" using in Laravel.
It supports following commands to execute.
  1. php artisan list
  2. php artisan –version
  3. php artisan down
  4. php artisan help
  5. php artisan up
  6. php artisan make:controller
  7. php artisan make:mail
  8. php artisan make:model
  9. php artisan make:migration
  10. php artisan make:middleware
  11. php artisan make:auth
  12. php artisan make:provider etc.


Question: What is laravel Service container?
Service Container is a powerful tool which is used to manage class dependencies and perform dependency injection.


Question: How to get last inserted id using laravel query?
$blogObj = new Blog;
$blogObj->title = "Web technology experts notes";
$blogObj->save(); //Save the data 
echo $blogObj->id // Return the last inserted id


Question: How to use mail() in laravel?
Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
    $m->from('from@example.com', 'Send Name');
    $m->to('receiver@example.com', 'Receiver Name')->subject('Your Reminder!');
});


Question: What is Auth?
Auth is in-built functionality provided by Laravel to identifying the user credentials with the database.


Question: How to make a constant? and how to use?
Add element in constants.php which should be in config folder.
return [
    'EMAIL_FROM' => 'from@example.com',
];

Get the value from config file.
echo Config::get('constants.EMAIL_FROM');//from@example.com



Question: What is with() in Laravel?
with() function is used to eager load in Laravel.


Question: How to get user’s ip address in laravel?
request()->ip()



Question: Difference between softDelete() & delete() in Laravel?
delete(): Record delete permanently.
softDelete(): records did not remove from the table only delele_at value updated with current date and time.


Question: How to enable query log in laravel?
DB::connection()->enableQueryLog();
$querieslog = DB::getQueryLog();
dd($querieslog) //Print the logs



Question: How to use skip() and take() in Laravel Query?
$posts = DB::table('blog')->skip(5)->take(10)->get();


Question: Give the list of Design Patterns in Laravel?
  1. The Builder pattern
  2. The Repository pattern
  3. The need for the Builder pattern
  4. The need for the Factory pattern
  5. The Factory pattern
  6. The Provider pattern
  7. The Facade pattern
  8. The Strategy pattern

Question: What are views?
Views contain the HTML provided by our application (UI part).


Question: What is faker in Laravel?
Faker is a type of module or packages which are used to create fake data for testing purposes.