Top 51 Laravel interview Question and Answer for all version
Question1 - What is Laravel and Why Laravel Used?
Ans:- Laravel is an open-source PHP framework. This framework was intended for the development of web application and mobile Application Api handle by using MVC architectural pattern. Why Laravel is most popular like node js, python ,asp.net because Laravel easy to write the api .
Question2) What is composer?
Ans:- composer is an application package to manager for PHP libraries and software dependencies.
Question3) What is middleware in Laravel?
Ans:- Laravel middleware that checks whether application user is authenticated or not. they are using to handle security purpose for all user like external and internal user.
The above pic of Laravel Middleware
Custom middleware are created like AdminMiddleware.php, CompanyAdminMiddleware.php, userMiddleware.php
All above pic are custom created Middleware the logic is
if(Auth::user()['role_type'] == 1)
return $next($request);
handle by role type
And laravel default middleware are :
CheckForMaintenanceMode
EncryptCookies
RedirectIfAuthenticated
TrimStrings
TrustProxies
VerifyCsrfToken
4) What the Name aggregates methods of query builder?.
Ans: The query builder used this name max(), 2) min(), 3) sum(), 4) avg(), and 5) count()
Example
User::where('type',1)->count(id);
User::where('verify',1)->sum(salary);
5) You Know Route?
Ans: Route are used to move one page to another page through url
basically two type of route
1- static
2- dynamic
example:
Route::get('verify-user/{emailid}/{key}', 'FontEndController@verifyIndivisualUser');
7) What do you mean by bundles?
Ans :- Bundles is like package .that increase the functionality of view , config , migrations, routes, and using controller function like hash .
8) Explain directories used in Laravel application.
Ans :
Bootstrap : In this folder there are using app.php ans cache
- Config: the app's configuration files. These are usually not modified directly but instead, values set up in the .env file at the root of the app.
- Database/: The database folder files, including migrations, seeds, and test factories.
9 How to write simple get api in laravel all version?
Ans . First you want to create a model example model name . StudentModel
Then create controller like StudentController and write the code inside the controller
public function getStudentData(){
$sdata =StudentData::all();
return Response::json($sdata);
}
After that write the rotues inside the route folder
Route::get('getstudentdata', 'StudentController @getStudentData');
10 How to write parameter get api in laravel all version?
Ans .
Pass the parameter on frontend page
public function getStudentDatabyid(Request $request){
$data = $request->all();
$s-data =StudentData::where('id', $data->id)->get();
return Response::json($s-data);
}
After that write the rotues inside the route folder
Route::get('getstudentdatabyid', 'StudentController @getStudentDatabyid');
11 How to write parameter post api in laravel all version?
Suppose that multiple field update in database write the post update api
public function getupdateStudentDatabyid(Request $request){
$data = $request->all();
$updatedata =StudentData::where('id', $data->id)->Update([''name'=>$data['name'],'address'=>$data['address']);
$status='succesfully update';
return Response::json($status);
}
Route::post('updatestudentdata', 'StudentController @getupdateStudentDatabyid');
12 Difference b/w post method and get method for laravel ?
a- get method without any parameter call but post method doesnot call
b- get method minimum data send and post method larage amount of data send.
c- In get method only pass parameter data and post method pass both data parameter and body
d-get method parameter show in url but post method does not show in url.
13) Describe reverse routing in Laravel all version?.
Ans Reverse routing is a type of method for generating URL based on symbol or name type. using this features Laravel make an application is flexible.
14) Describe traits in Laravel.
Ans Laravel traits make a controller to use and call the external api login and registration and simply do not default vendor file change and change the functionality in laravel.
15) How to define Laravel's Facades?
Ans Laravel have defined in Illuminate\Support\Facades namespace. Facades are use for installation package functionality .
16) Describe dependency injection and their types.
Ans dependency injection one object is dependent on another object. There are different types of dependency injection: a) Constructor injection, b) setter injection, and c) interface injection.
17) What is ORM stand for?
ORM stands for Object Relational Mapping .it is using for relation between database like one to one , one to many, many to many.
18) How can you fast in Laravel?
You can use the cursor method in order to reduce memory usage.
Remove the all cache in laravel.
27) Which Template Engine used Laravel.
Ans Blade.
28) Laravel databases supported are ? .
Laravel supports four type databases:
- PostgreSQL
- SQL Server
- SQLite
- MySQL
kikkkkkkkkkkkkkkkkkk
ReplyDeletehttps://www.guru99.com/laravel-interview-questions.html
ReplyDelete