Laravel Interview Question and Answer

What is laravel ?

Laravel is an open source PHP framework. It is intended for development of web application by using MVC architecture pattern, It is released under MIT licence
Laravel is a widely used framework and it follows accurate language rules.

What are the benefits of Laravel Framework?
a) It support multiple file system
b) It has inbuilt Authentication System
c) It use Eloquent ORM (Object Relation Mapping)
d) Laravel has Pre Loaded packages eg: Cashier, Scout, Passport, Socialite
e) Laravel use Artisan for creating code skeleton , migration and database structure.

What is migration in Laravel ?
Migration is like a version control for easily modify and share the application database schema, migration are typically paired with laravel’s schema builder to easily build the application’s database schema. Migration is used for creating database table
php artisan make:migration create_users_table

What is Cashier in database ?
Laravel Cashier implements an expressive, fluid interface to Stripe and Braintree’s subscription billing service. It controls all of the boilerplate subscription billing codes. The cashier can also manage coupons, subscription quantities grace periods for cancellation and even create PDF invoice

What is passport in Laravel ?
Passport is used for API authenticatin , it offers Oauth2 server implementation for laravel , typically passport is built on top of the Alex Bilbie maintained League OAuth2 server

What is Scout in Laravel ?
Using the scout we can do the full text search using eloquent models and it also help to maintain search index in sync with eloquent records using model observers.

What is Socialite in Laravel ?
For implementation third party login socialite is used like Facebook, Google, Facebook etc, It controll all boilerplate authentication codes.

What is soft delete and how to implement in laravel ?
Rather than delete a record from database permanently we can use some flag or timestamp

using the trait in model we can add soft delete feature in laravel

example:

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class User extend Model {

use SoftDeletes;

protected $table = 'users';

//code
}

How to do request validation in Laravel ?
Using the controller method we can do the request validation in laravel
example:

public function user(Request $request){
$validated = $request->validate([
'name' => 'required|max:255',
'address' => 'required'
]);

//code
}

What is the use of ‘Artisan’ command line in Laravel ?
It use the ‘make’ command for creating the files for contrlloer, model , migration etc.
eg:

php artisan make:controller : it is used for make the controller file
php artisan make:model : it is used for make the model file
php artisan make:seeder : it is used for make the seeder file
php artisan make:migration -: is used for make migration file
php artisan make:command -: is used for make the custom artisan command

Leave a Reply

Your email address will not be published. Required fields are marked *