Quick Contact


    Laravel PHP QUESTION ANSWERS

    Q1- Explain LTS Version of Laravel?

    LTS means Long Term Support. It is used for bugfixes for which version is provided until the next version. Latest LTS versions are used i.e. Laravel 5.1 or Laravel 5.5. Bugfixes for LTS laravel version are continued until next version arrives but Non LTS Version bugfixes provided only for 6 months.

    Q2-: What is PHP Artisan Command?

    This command is known to be as command-line user interface and helps to build the application. To check the complete list of all available Artisan commands- write- “php artisan list”. Go to Command Prompt and Use this command you can see all Laravel artisan command. Some more Php commands are -:

    1. Php artisan cache:clear-

      To clear the cache

    2. Php artisan view:clear-

      To clear view cache

    3. Php artisan route:cache-

      To clear route cache

    4. Php artisan config:cache-

      To clear config cache

    Q3-: How can extend login expire time in login Auth.?

    To increase or decrease expire time Gotoconfig>auth.php

    
    	Changes expire time as-:
    	     	‘Passwords’=> [
    	       	‘Users’=> [
    	       	‘Provider’ => ‘users’,
    	       	‘Table’ => ‘password_resets’,
    	        ‘expire’ => 60,
          ],
         ],
    	
    Q4-: How many routes generate by Auth::routes ();?

    Routes in -:

    1. //Authentication Routes…

      $this->get(‘login’,’Auth\LoginController@showLoginForm’)->name(‘login’);

      $this->post(‘login’,’Auth\LoginController@login’);

      $this->post(‘logout’, ‘Auth\LoginController@logout’)->name(‘logout’);

    2. //Registration Routes…

      $this->get(‘resgister’, ‘Auth\RegisterController@showRegistrationForm’)-

      $this->get(‘resgister’, ‘Auth\RegisterController@showRegistrationForm’)->name(‘register’);

      $this->post(‘register’, ‘Auth\RegisterController@register’);

    3. //Power Reset Routes…

      $this->get(‘password/reset’, ‘Auth\ForgetPasswordController@showLinkRequestForm’);

      $this->post(‘password/email’, ‘Auth\ForgotPasswordController@sendResetLinkEmail’);

      $this->get(‘password/reset/{token}’, ‘Auth\Reset PasswordController@showResetForm’);

      $this->post (‘password/reset’,’Auth\ResetPasswordController@reset’);

    Q5-: What is Eloquent ORM?

    Eloquent ORM is Object-Relational Mapping is important feature of Laravel framework which is used for active record pattern. In active record the class is directly map to database table. But with using Eloquent, every database table contains the corresponding “model” which is used for interaction with that respective table.

    Example class User =-> database table users.

    So here class user can directly access or use the database table of users.

    Q6-: Explain query builder in Laravel?

    Query builder provides direct access to database, as it is alternative to Eloquent ORM. SQL queries are not required to be directly written. It provides or offers a set of class as well as methods that are capable for build queries programmatically. It also allows specific caching of results of executed queries as-:

    $affected = DB::table (‘users’)

    ->where (‘id’, 1)

    ->update ([‘votes’ => 1]);

    As if you donot want access through Eloquent ORM in any table then you can use this as alternative.

    Q7-: what are directories used in common Laravel application?

    Directories used in CLA are-:

    App/:

    This is taken as source folder where there is application code is saved and executed. All policies, models and controllers are present inside the folder.

    Config/:

    It contains application configuration file which are not modified but instead rely on values present in the environment i.e. .env file at the root of the app.

    Database/:

    It considers database files also included with seeds, migrations and test factories.

    Database/:

    It considers database files also included with seeds, migrations and test factories.

    Public/:

    It describe publicly accessible folder which contains compiled assets and also an index.php file.

    Q8-: What are advantages of using Laravel?
    • It is very useful for creating dynamic layouts due to the presence of blade template engine which increases the compiling tasks.
    • Code can be reused without any error or hassle.
    • Laravel use advance query builder mechanism that helps to enforce constraints within different or multiple DBM objects.
    • Its framework has auto-loading feature, so no need to do manual maintenance and inclusion paths.
    • It helps to make new tools in framework using LOC container.
    • In this version control system is available which helps with simplified management of migrations.
    Q9-: Explain validation in Laravel?

    In designing of the applications validations are important concept needed which helps to ensure the data in expected format to store in database. It has multiple ways for validation. Base controller trait is there in which Validate Requests class is used which is a useful method to validate the requests receives from client machine.

    Q10-: What is common artisan commands used in Laravel?

    Artisan commands in Laravel-:

    • PHP artisan down;
    • PHP artisan up
    • PHP artisan make: controller
    • PHP artisan make: model
    • PHP artisan make: migration
    • PHP artisan make: middleware
    Q11-: Explain insert () and insertGetId() function and write the basic concepts in Laravel?
    Insert ():

    This function is used to insert the record into database; in this Id incrementation is not necessary.

    InsertGetID ():

    It is also used to insert the records in the table but in this function runs when ID field is auto-incremented.

    The basic concepts are-:

    • Routing
    • Eloquent ORM
    • Middleware
    • Security
    • Caching
    • Blade Templating
    Q12-: What is MVC framework? Explain Auth.?

    It means Model, View and Controller.

    In which Model tells the logic to write Laravel application, where View explains the UI logic of application and controller works as an interface between model and view that include the interaction of user with application.

    Where Auth is method to identify login credential with a password which is managed with session that includes two parameters- username and password.

    Q13-: What is Laravel and how MVC architecture is related?

    Laravel is open source framework of PHP which follows MVC architecture, a pattern used to develop web applications. It is created by Taylor Otwell in 2011.

    Where MVC i.e. model view controller is a pattern which is a way to organize the code which is written by differentiate into three parts i.e. models, views and controller. It separate application code from presentation code. As you can see in several IT companies there are few developers or designers that are working on the creating functions, designers create blade files etc. so everything is separate they are working on different modules. So, MVC helps to do different functions together. So, MVC reduces the time and effort and helps to separate the code so it is very useful for the modern PHP developed applications.

    Q14-: What are the versions required of Laravel and tell the requirement of Php for Laravel respective versions? Explain Composer?

    The current version of Laravel is Laravel 8 and Future version of Laravel is Laravel 9. Requirement of PHP for Laravel 8 and 9 is PHP>=7.3 and PHP 8 respectively.

    Whereas Composer is basically helps to install Laravel packages, components, install Laravel but not only Laravel composer also use in another PHP frameworks as well, so it is kind of a package tool. Moreover Composer is package management tool which helps in installing packages like intervention etc. Composer also helps to update and install the packages as well as components for Laravel projects.

    Q15-: Write Templating engine used for Laravel and which database is supported by Laravel?

    Templating engine used is known as blade and the blade file extension is .blade.php extension and the databases used are-:

    • PostgreSQL
    • MySQL
    • SQLite
    • SQL Server
    Q16-: Explain artisan?

    It is actually command interface which helps to run various commands for making models, controllers etc., and so many commands depend on the artisan. As artisan is CL (command line tool) or interface for Laravel which helps the developer to build application. Common artisan commands are-:

    – Php artisan serves – to run the project of Laravel.

    – Php artisan make: controller- to build controller file.

    – Php artisan make: model- use to make model file.

    – Php artisan make: migration- use to make migration file to create table.

    – Php artisan make: seeder – to make seeder file use to insert data in table.

    Q17-: What are new features and new upcoming versions of Laravel?

    Upcoming versions are-:

    – Laravel 9 is next LTS version which is released at end of jan 2022.

    – Laravel 9- bug fix the support until 30th January, 2024.

    – Laravel 9- security fixes support- until January 28, 2025.

    – Laravel 10 is further expected to release –January, 2023

    – Laravel 11 is expected to release in 2024, January.

    New Features are-:

    – PHP 8 is required for PHP version updation, it has anonymous stub migrations as well as PHP 8 string functions. So, in Laravel 9 new query builder interface

    Q18-: Explain how to create auth.? What is service container?

    There are some commands used to run in Laravel to install auth.

    As in Laravel 6 following commands are used to run as-:

    – Composer require Laravel/ui “^1.0” –dev

    – Php artisan uivue –auth

    – Php artisan migrate

    Before Laravel 6 the commands were used-:

    – Php artisan make:auth

    – Php artisan migrate

    Service container is a tool to manage class dependencies and perform dependency injection. Whereas class dependency is known to be where class is depend on other.

    For dependency injection: class dependencies- injected into class via constructor or in some cases, “setter” method is required.

    For example as go to-:

    App->Providers->AppServiceProvider.php then you get registered method as in-:

    Class AppServiceProvider

    $this->app->bind(UserClass::class, function($app)

    {

    Return newUserClass();

    }

    );

    Class Home Controller

    Public $user;

    Publicfunction_construct(UserClass $user){

    $this->testuser-$user;

    }

    Q19-: What is Laravel chunk () and Laravelcursor()?

    Chunk is useful if you will work for thousands of database records, it will split the query into small queries and it is beneficial to reduce the memory usage. It is used as-:

    DB::table(‘users’)->orderBy(‘id’)->chunk(100, function ($users){

    Foreach ($users as $user) {

    Echo $user->name;

    }

    });

    Whereas Laravel cursor () is a method to fetch the records of database by using cursor that will only execute the single query. It is used to reduce memory usage. It is used as-:

    Foreach (DB::table (‘user’)->orderBy(‘id’)->cursor() as $user) {

    Echo $user->name;

    }

    Q20-: Explain reverse routing?

    Reverse routing tells or defines the relationship between Laravel routes and links. In this when the link is created in which names of existing routes are used as well as using appropriate Uri’s are created automatically by Larvel. As take a file of web.php in which different routes are created in which uri’s are called so in reverse routing you can apply same function in different or reverse way such as-:

    Web.php

    Route::get(‘aboutus’, ‘Usercontroller@aboutus’);

    Route::get(‘contactus’, ‘usercontroller@contactus’);

    Route::get(‘userregister’, ‘Usercontroller@userregister’);

    In Reverse Routing

    {{ HTML::link_to_action(‘Usercontroller@aboutus’) }}

    You will create aboutusurl

    Q21-: Explain façade?

    Façade provide interface i.e. “Static” interface to classes.

    DB::table(‘student’)->get();

    In Laravel there are many facades

    For example-:

    ‘DB’ => Illuminate\Support\Facades\DB:: class,

    ‘Session’ => illuminate\Support\Facades\Session:: class,

    ‘Request’ => illuminate\Support\Facades\Request:: class,

    ‘Validator’ => illuminate\Support\Facades\Validator:: class,

    You can see all available facades in config->app.php

    Q22-: How to create Façade?

    Suppose create ‘Testclass’ name folder in which a class is created of “MyTest” in which show () name function is created in class. As show () is non-static function, to call non-static function, object is created. But if you build a Façade () class is created in same folder i.e. “testclass”. First class is imported in façade class then façade class is extended then creates routes and aliases. Aliases are included in route in which façade class is required. So in this way all non-static functions in class can use as static function.

    So following is wriiten about how to create class, façade class, aliases and routes-:

    CREATE CLASS-:

    Namespace App\Testclass;

    classMyTest{

    Public function show (){

    Echo “This is show function”;

    }

    }

    FAÇADE CLASS-:

    Namespace App\Testclass;

    Use illuminate\support\facades\facade;

    Class UserFacade extends Façade{

    Protected static function getFacadeAccessor(){

    Return new MyTest();

    }}

    CREATE ALIASES

    Config->app.php

    ‘MyFacade’=>\App\Testclass\UserFacade::class,

    ROUTES-:

    Route::get (‘showtest’,function(){

    MyFacade:: show();

    });

    Q23-: Explain Middleware?

    It provides the easy or convenient mechanism which does the filtering HTTP requests entering your application as-: app/Http/Kernel.php. When you request a query then it firsts check in middleware and after that the query will be handles by controller. For example you create user login section in which Uri’s are created so if you put condition that only login user will only login with that id, so that matching credentials will check in middleware. So the sub url will not executed until it will verify as a user with matching credentials which will check in middleware.

    There are three types of middleware-:

    1. Global middleware
    2. Assigning middleware to routes
    3. Group middleware
    Q24-: Define global middleware, assigning middleware to routes and group middleware?
    1. Global middleware is used to run with your every HTTP request to the application.
    2. Assigning middleware-: It is used if you want to assign specific middleware to the request so you can do it. So for this create middleware due to which when you hit respective url then it call assigning middleware and then pass according to it.

    Protected $routeMiddleware = [

    ‘auth’ => \App\Http\Middleware\Authenticate::class,’

    ‘auth.basic’ => \illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,

    ‘bindings’ => \illuminate\Routing\Middleware\SubstituteBindings::class,

    ];

    Route::get(‘admin/profile’.function() {

    //

    })->middleware(‘auth’);

    GROUP MIDDLEWARE-:

    You can also apply middleware groupwise as-:

    Q25-: What are the features of Laravel framework?
    1. Template engine-:

      Laravel framework recognized for built-in lightweight templates which helps to create stunning design, also having multiple widgets. Templates are created with simple design with distinctive sections.

    2. Bundles-:

      It has small packages which are downloaded to add functionality to web application.

    3. Unit-testing-:

      It is very important part in which hundreds of tests are run after new changes. It is most stable released framework. It is easy to write unit-tests for the code.

    4. Elequent ORM (object relational mapping)-:

      It includes simple PHP Active Record implementation. An ORM is faster than all other PHP framework.

    5. Routing system-:

      It is simple and easy approach to routing. It is more flexible and control over the route which is triggered on application.

    6. Restful controllers-:

      These are optional ways to separate the POST and GET request logic.

    7. Libraries and modular-:

      Laravel has pre-installed libraries as well as object oriented libraries. Pre- installed libraries are not found in other php frameworks. One of the pre-installed libraries is authentication library, it is easy to implement and has many latest features. This framework is divided into individual modules.

    8. Security-:

      It’s about providing security to web application development such as Bcrypt hashing etc.

    Copyright 1999- Ducat Creative, All rights reserved.