Showing posts with label Laravel. Show all posts
Showing posts with label Laravel. Show all posts

Sunday 5 April 2020

Laravel interview questions for 4 year experienced

Laravel interview questions for 4 year experienced

Question: What is Server Requirements for Laravel 5.6?
  1. PHP >= 7.1.3
  2. PDO PHP Extension
  3. Ctype PHP Extension
  4. OpenSSL PHP Extension
  5. XML PHP Extension
  6. JSON PHP Extension
  7. Mbstring PHP Extension
  8. Tokenizer PHP Extension

Question: What is Laravel Dusk?
It is expressive, easy-to-use browser automation and testing API.


Question: What is Laravel Echo?
Event broadcasting, evolved. Bring the power of WebSockets to your application without the complexity.


Question: How to Install Laravel via Composer?
composer create-project --prefer-dist laravel/laravel myproject



Question: How to Install any Specific version of Laravel via Composer
composer create-project --prefer-dist laravel/laravel blog "5.4.*" //Install Laravel 5.4 using Composer



Question: What is Lumen?
  1. Lumen is a micro-framework provided by Laravel.
  2. It is developed by creator of Laravel Taylor Otwell.
  3. It is mostly used for creating RESTful API's & microservices.
  4. Lumen is built on top components of Laravel.



Question: How to Install Lumen via Composer?
composer create-project --prefer-dist laravel/lumen myproject



Question: List benefits of using Laravel over other PHP frameworks?
  1. Artisan
  2. Migrations & Seeding
  3. Blade Template Engine
  4. Middleware - HTTP middleware provide a convenient mechanism for filtering HTTP requests
  5. Routing (RESTful routing)
  6. Authentication, Cashier, Scheduler, SSH, Socialite
  7. Security
  8. Unit Testing
  9. Caching


Question: Which Template Engine used by Laravel?
Blade is the simple, yet powerful templating engine provided with Laravel.


Question: How to enable maintenance mode in Laravel?
// Enable maintenance mode
php artisan down

// Disable maintenance mode
php artisan up



Question: What are Closures in Laravel?
A Closure is an anonymous function. Closures are often used as a callback methods and can be used as a parameter in a function.


Question: List out databases that laravel supports?
MySQL
PostgreSQL
SQLite
SQL Server


Question: How To Use Insert Query In Laravel?
class UserController extends Controller
{
    /**
     * Create a new user instance.
     *
     * @param  Request  $request
     * @return Response
     */
    public function store(Request $request)
    {
        $user = new User;
        $user->name = $request->name;
        $user->role = $request->role;
        $user->save();
    }



Question: What are the available Router Methods?
Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);



Question: How To Use Update Query In Laravel?
$result = User::where('id',1)->update(['name'=>'My web technology experts notes']);



Question: How To Use Delete Query In Laravel?
$result = User::where('id',$id)->delete();



Question: What is Response in Laravel?
Following are different type of responses?
  1. View Responses
  2. JSON Responses
  3. File Downloads
  4. File Responses
  5. Response Macros
  6. Redirecting To Named Routes
  7. Redirecting To Controller Actions
  8. Redirecting To External Domains
  9. Redirecting With Flashed Session Data



Question: How to get current environment in Laravel?
$environment = App::environment();


Question: Where do you locate database configuration file?
Migrations are like version control for your database, that's allow to easily modify and share the application's database schema. Migrations are typically paired with Laravel's schema builder to easily build your application's database schema.


Question: What are laravel 6 features?
  1. Inbuilt CRSF (cross-site request forgery ) Protection.
  2. Inbuilt paginations
  3. Reverse Routing
  4. Query builder
  5. Route caching
  6. Database Migration
  7. IOC (Inverse of Control) .
  8. Job middleware
  9. Lazy collections



Friday 3 April 2020

Laravel interview questions for 3 year experienced

Laravel interview questions for 3 year experienced

Question: Explain validation in Laravel.?
ValidatesRequests is the trait which is been used by Laravel classes for validating input data.
public function store(Request $request)
{
   $validatedData = $request->validate([
       'title' => 'required|unique:posts|max:255',
       'description' => 'required',
       'email' => 'required',
   ]);
}



Question: What is CSRF protection and CSRF token?
Cross-site forgeries are a type of malicious exploit where unauthorized person/command do/run on behalf of the authenticated user.
Laravel generates a CSRF "token" automatically for each active user session.
This token is used to verify that the authenticated user is the one actually making the requests.


Question: What is Laravel Dusk?
It is expressive, easy-to-use browser automation and testing API.


Question: What is Laravel Echo?
Event broadcasting, evolved. Bring the power of WebSockets to your application without the complexity.


Question: How do you install Laravel?
Laravel utilizes Composer to manage its dependencies. So, before using Laravel, make sure we have Composer installed on your machine.


Question: Explain Binding Instances?
You may also bind an existing object instance into the container using the instance method.
$api = new HelpSpot\API(new HttpClient);
$this->app->instance("HelpSpot\API", $api);



Question: Explain Extending Bindings?
$this->app->extend(Service::class, function($service) {
    return new DecoratedService($service);
});



Question: What is the make Method?
You may use the make method to resolve a class instance out of the container.
$api = $this->app->make("HelpSpot\API");



Question: What is Register Method?
within the register method, you should only bind things into the service container.


Question: What is the Boot Method?
if we need to register a view composer within our service provider? This should be done within the boot method.


Question: Where do you regiser service providers?
config/app.php configuration file


Question: What are Laravel’s Contracts?
Laravel’s Contracts are a set of interfaces that define the core services provided by the framework.


Question: Give example of Router?
Route::get("foo", function () {
return "Hello World";
});



Question: What are the available Router Methods?
Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);



Question: How to 301 redirect in laravel (permanent redirect)
Route::redirect("/old", "/new", 301);



Question: How to 302 redirectin laravel (temporary redirect)
Route::redirect("/old", "/new", 302);



Question: What are Middleware Groups?
Sometimes you may want to group several middleware under a single key to make them easier to assign to routes.


Question: What are Redirect responses?
Redirect responses are instances of the Illuminate\Http\RedirectResponse class, and contain the proper headers needed to redirect the user to another URL.


Question: Where do you locate database configuration file?
The database configuration for your application is located at config/database.php.


Question: What are Blade Templates?
Blade is the simple, yet powerful templating engine provided with Laravel.


Wednesday 1 April 2020

Laravel interview questions for 2 year experienced

Laravel interview questions for 2 year experienced

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



Question: What do you mean by bundles?
Bundles are referred to as packages in Laravel. These packages are used to increase the functionality of Laravel.


Question: Explain important directories used in a common Laravel application.?
App/ : This is a source folder where our application code lives. All controllers, policies, and models are in this folder.
Config/ : Here are configuration files.
Database/: Houses the database files, including migrations, seeds, and test factories.
Public/: Publicly accessible folder holding compiled assets and of course an index.php file.


Question: Explain reverse routing in Laravel.
Reverse routing is a method of generating URL based on symbol or name. It makes your Laravel application flexible.


Question: Define Lumen?
Lumen framework is a smaller, and faster, version of a building Laravel based services, and REST API's.


Question: How can you generate URLs?
Laravel has helpers to generate URLs.


Question: Explain faker in Laravel?
It is a type of module or packages which are used to create fake data. This data can be used for testing purpose.


Question: List basic concepts in Laravel?
  1. Routing
  2. Eloquent ORM
  3. Middleware
  4. Security
  5. Caching
  6. Blade Templating



Question: What is Eloquent?
Eloquent is an ORM used in Laravel. It provides simple active record implementation working with the database.


Question: What is the use of DB facade?
DB facade is used to run SQL queries like create, select, update, insert, and delete.


Question: What is a session in Laravel?
Session is used to pass user information from one web page to another.
Support for cookie, array, file, Memcached, and Redis to handle session data.


Question: Explain to listeners?
Listeners are used to handling events and exceptions.


Question: What are policies classes?
Policies classes include authorization logic of Laravel application.


Question: What is an Observer? Observeris used to make clusters of event listeners for a model.
Method names of these classes depict the Eloquent event. Observers classes methods receive the model as an argument.

Question: What is the use of the bootstrap directory?
It is used to initialize a Laravel project. This bootstrap directory contains app.php file.


Question: Where will you define Laravel's Facades?
In Illuminate\Support\Facades namespace.


Question: Name databases supported by Laravel.
  1. MySQL
  2. SQLite
  3. SQL Server
  4. PostgreSQL



Question: What is the default session timeout duration?
2 hours.


Question: How to remove a complied class file?
Use clear-compiled command.


Question: In which folder robot.txt is placed?
Robot.txt file is placed in Public directory.


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.


Saturday 28 March 2020

Laravel Interview Questions and answers

Laravel Interview Questions and answers

Question: What is Laravel?
Laravel is a free and open-source PHP framework that follows the model–view–controller design pattern.


Question: What is the latest version of Laravel?
7.0, released on 3rd March 2020.


Question: Who created Laravel?
Taylor Otwell


Question: Who created Laravel?
Taylor Otwell


Question: What language does Laravel use?
PHP


Question: Which is the best IDE for Laravel?
Netbeans,
PhpStorm,
Atom,
Sublime Text


Question: Features of Laravel?
  1. Eloquent ORM
  2. Reverse routing
  3. Restful controllers
  4. Migrations
  5. Unit testing
  6. Automatic pagination
  7. Database Seeding
  8. Query builder available



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: How to extend login expire time in Auth?
Open config\session.php file and add/update following key's value.
'lifetime' => 180



Question: What is middleware in Laravel?
Middleware operates as a bridge and filtering mechanism between a request and response.


Question: How to pass CSRF token with ajax request?
In between head, tag put
[meta name="csrf-token" content="{{ csrf_token() }}"]


In Ajax, we have to add
$.ajaxSetup({
   headers: {
     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
   }
});



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


Question: How to use session in laravel?
Retrieving Data from session
session()->get('key');

Retrieving All session data
session()->all();

Remove data from session
session()->forget('key');

Storing Data in session
session()->put('key', 'value');


Saturday 28 July 2018

Laravel Basics for Beginners

Laravel Basics for Beginners

Question: What is Laravel?
Laravel is a open-source PHP framework used for Developing the websites.


Question: What developed the Laravel?
Taylor Otwell.


Question: When Laravel was launched?
June 2011


Question: What is current stable version of Laravel?
Version 5.2.36 dated June 6, 2016


Question: In which language it was written?
PHP.


Question: What is offical website URL of Laravel?
laravel.com.


Question: Is Laravel an Open Source?
Yes, Download the framework and use as per your requirement


Question: How to install Laravel?
We can install the Laravel in following ways.
  1. Laravel Installer
  2. Composer Create-Project



Question: Explain about Laravel Project?
Laravel is one of the most popular PHP frameworks used for Web Development.
This framework is with expressive, elegant syntax.
It is based on model–view–controller (MVC) architectural pattern.


Question: What are the feature of Laravel5.0?
  1. Method injection
  2. Contracts
  3. Route caching
  4. Events object
  5. Multiple file system
  6. Authentication Scaffolding
  7. dotenv – Environmental Detection
  8. Laravel Scheduler



Question: What is system requirement for installation of Laravel 5.2 (latest version)?
  1. PHP >= 5.5.9
  2. OpenSSL PHP Extension
  3. PDO PHP Extension
  4. Mbstring PHP Extension
  5. Tokenizer PHP Extension



Question: How to install Laravel5.0/Laravel 5.1 with detail steps?
Install Laravel 5.0
Install Laravel 5.1


Tuesday 2 August 2016

How to install Laravel 5 on wamp server

How to install Laravel 5 on wamp server

We are going to install Laravel5.0 on wamp server in windows.


Question: What are system requirement for laravel5.0?
Following are system requirements:
  1. PHP >= 5.4, PHP < 7
  2. Mcrypt PHP Extension
  3. OpenSSL PHP Extension
  4. Mbstring PHP Extension
  5. Tokenizer PHP Extension



Question: How to install Laravel5.0?
  1. You must have composer. If not install composer.
  2. Create a folder where you want to install the laravel. Supppose
    E:\wamp\www\laravel
  3. Login to Command Prompt and go the "E:\wamp\www\laravel" using cd command.
  4. Execute following command
    composer create-project laravel/laravel laravel "5.0.*" --prefer-dist
  5. Set the document_path to "E:\wamp\www\laravel\public" OR You can use virtual host for this. In any ways file must point to public folder first.



Monday 1 August 2016

Laravel cache interview questions and answers


Question: How to Store an value in cache?
$expiresAt = Carbon::now()->addMinutes(10);
Cache::put('name', 'My Name is Anurag', $expiresAt); //store for 20 mins



Question: How to Check an value stored in cache?
if (Cache::has('name'))
{
    
}



Question: How to Get an value stored in cache?
if (Cache::has('name'))
{
    $name = Cache::get('name');//My Name is Anurag
    
}



Question: How to Get an value from cache, If Not set get Default?
    $name = Cache::get('name2','unknown');//Return "unknown"



Question: How to Store an value in cache Permanently?
Cache::forever('name', 'My Name is Anurag'); //store Permanently



Question: Get value from cache, If not then set a default value?
$expiresAt = Carbon::now()->addMinutes(10);
$value = Cache::remember('users', $expiresAt, function(){
    return DB::table('users')->get();
});



Question: Get value from cache, If not then Delete?
$value = Cache::pull('name');



Question: Remove an Item from cache?
Cache::forget('name');



Question: Store an Integer value in cache?
Cache::put('sr', 10);



Question: Increase the Integer value in cache?
Cache::increment('sr');//change from 10 to 11



Question: Decrease the Integer value in cache?
Cache::decrement('sr');//change from 11 to 10



Question: Store an value in cache with tag?
Cache::tags('Tag1','Tag2')->put('name', 'My Name is Anurag', $minutes);



Friday 29 July 2016

Laravel Interview Questions and Answers

Laravel Interview Questions and Answers

Question: What is Laravel?
Laravel is a open-source PHP framework developed by Taylor Otwell used for Developing the websites.
Laravel helps you create applications using simple, expressive syntax.


Question: What are Advantages of Laravel?
  1. Easy and consistent syntax
  2. Set-up process is easy
  3. customization process is easy
  4. code is always regimented with Laravel



Question: Explain about Laravel Project?
Laravel is one of the most popular PHP frameworks used for Web Development.
This framework is with expressive, elegant syntax.
It is based on model–view–controller (MVC) architectural pattern.


Question: What are the feature of Laravel5.0?
  1. Method injection
  2. Contracts
  3. Route caching
  4. Events object
  5. Multiple file system
  6. Authentication Scaffolding
  7. dotenv – Environmental Detection
  8. Laravel Scheduler



Question: Compare Laravel with Codeigniter?
Laravel Codeigniter
Laravel is a framework with expressive, elegant syntax CodeIgniter is a powerful PHP framework
Development is enjoyable, creative experience Simple and elegant toolkit to create full-featured web applications.
Laravel is built for latest version of PHP Codeigniter is an older more mature framework
It is more object oriented compared to CodeIgniter. It is less object oriented compared to Laravel.
Laravel community is still small, but it is growing very fast. Codeigniter community is large.



Question: What are Bundles,Reverse Routing and The IoC container ?
Bundles: These are small functionality which you may download to add to your web application.
Reverse Routing: This allows you to change your routes and application will update all of the relevant links as per this link.
IoC container: It gives you Control gives you a method for generating new objects and optionally instantiating and referencing singletons.



Question: How to set Database connection in Laravel?
Database configuration file path is : config/database.php
Following are sample of database file
 
'mysql' => [
    'read' => [
        'host' => 'localhost',
    ],
    'write' => [
        'host' => 'localhost'
    ],
    'driver'    => 'mysql',
    'database'  => 'database',
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
],
 



Question: How to enable the Query Logging?
DB::connection()->enableQueryLog();



Question: How to use select query in Laravel?
$users = DB::select('select * from users where city_id = ?', 10);
if(!empty($users)){
    foreach($users as $user){

    }
} 



Question: How to use Insert Statement in Laravel?
DB::insert('insert into users (id, name, city_id) values (?, ?)', [1, 'Web technology',10]);



Question: How to use Update Statement in Laravel?
DB::update('update users set city_id = 10 where id = ?', [1015]);



Question: How to use Update Statement in Laravel?
DB::update('update users set city_id = 10 where id = ?', [1015]);



Question: How to use delete Statement in Laravel?
DB::delete('delete from  users where id = ?', [1015]);



Question: Does Laravel support caching?
Yes, Its provides.