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

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.