0% found this document useful (0 votes)
21 views

laravel (1)

Laravel is a web application framework created by Taylor Otwell, utilizing the MVC design pattern and offering an expressive syntax for rapid development. It has various pros such as a lightweight blade template engine and Eloquent ORM, but also cons including a steep learning curve and slower development compared to other frameworks. Key features include event handling, validation, database migrations, and a command line interface called PHP artisan for managing application tasks.

Uploaded by

Loai Al-ayoubi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

laravel (1)

Laravel is a web application framework created by Taylor Otwell, utilizing the MVC design pattern and offering an expressive syntax for rapid development. It has various pros such as a lightweight blade template engine and Eloquent ORM, but also cons including a steep learning curve and slower development compared to other frameworks. Key features include event handling, validation, database migrations, and a command line interface called PHP artisan for managing application tasks.

Uploaded by

Loai Al-ayoubi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Q1. What is Laravel?

MVC design pattern.


It is created by Taylor Otwell. Laravel provides expressive and elegant syntax that
helps in creating a wonderful web application easily and quickly.

Q2. What are pros and cons of using Laravel Framework?

Pros of using Laravel Framework

1. Laravel framework has in-built lightweight blade template engine to speed


up compiling task and create layouts with dynamic content easily.
2. Hassles code reusability.
3. Eloquent ORM with PHP active record implementation
4.
database structure and build their migration

Cons of using laravel Framework

5. Development process requires you to work with standards and should have
real understanding of programming
6. Laravel is new framework and composer is not so strong in compare
to npm (for node.js), ruby gems and python pip.
7. Development in laravel is not so fast in compare to ruby on rails.
8. Laravel is lightweight so it has less inbuilt support in compare to django
and rails. But this problem can be solved by integrating third party tools,
but for large and very custom websites it may be a tedious task.

Q3. Explain Events in Laravel?

An event is an action or occurrence recognized by a program that may be handled


by the program or code. Laravel events provides a simple observer
implementation, that allowing you to subscribe and listen for various
events/actions that occur in your application.

All Event classes are generally stored in the app/Events directory, while their
listeners are stored in app/Listeners of your application.

Q4. Explain validations in Laravel?

In Programming validations are a handy way to ensure that your data is always in
a clean and expected format before it gets into your database. Laravel provides
several different ways to validate your application incoming data. By default
ValidatesRequests trait which provides a
convenient method to validate all incoming HTTP requests coming from client.
You can also validate data in Laravel by creating Form Request.
Q5. How to install laravel via composer ?

You can install Laravel via composer by running below command.

composer create-project laravel/laravel your-project-name version

Q6. List some features of laravel 5.0 ?

o Inbuilt CRSF (cross-site request forgery ) Protection.


o Inbuilt paginations
o Query builder
o Route caching
o Database Migration

Q7. What is PHP artisan. List out some artisan commands ?

PHP artisan is the command line interface/tool included with Laravel. It provides
a number of helpful commands that can help you while you build your application
easily. Here are the list of some artisan command:-

o php artisan list


o php artisan help
o php artisan tinker
o php artisan make
o php artisan versian
o php artisan make:model model_name
o php artisan make:controller controller_name

Q8. List some default packages provided by Laravel 5.6?

Below are list of some official/ default packages provided by Laravel 5.6

o Cashier
o Envoy
o Passport
o Scout
o Socialite
o Horizon

Q9. What are named routes in Laravel?

Named routing is another amazing feature of Laravel framework. Named routes


allow referring to routes when generating redirects or Urls more comfortably.
You can specify named routes by chaining the name method onto the route
definition:
Route::get('user/profile', function () {
//
})->name('profile');

You can specify route names for controller actions:

Route::get('user/profile', 'UserController@showProfile')->name('profile');

Once you have assigned a name to your routes, you may use the route's name
when generating URLs or redirects via the global route function:

// Generating URLs...
$url = route('profile');
// Generating Redirects...
return redirect()->route('profile');

Q10. What is database migration. How to create migration via artisan?

Migrations

database schema.

Use below commands to create migration data via artisan.

// creating Migration
php artisan make:migration create_users_table

Q13. What is composer?

Composer is a tool for managing dependency in PHP. It allows you to declare the
libraries on which your project depends on and will manage (install/update) them
for you.
Laravel utilizes Composer to manage its dependencies.

Q14. Explain Facades in Laravel?

Laravel Facades provides a static like an interface to classes that are available in
-ships with many facades which

ce container and provide benefits of a


terse, expressive syntax while maintaining more testability and flexibility than
Illuminate\Support\Facades namespace. You can easily access a facade like so:

use Illuminate\Support\Facades\Cache;

Route::get('/cache', function () {
return Cache::get('key');
});

Q15. What are Laravel Eloquent?

with your database. Laravel provide many different ways to interact with your
database, Eloquent is most notable of them. Each database table has a

you to query for data in your tables, as well as insert new records into the table.

Below is sample usage for querying and inserting new records in Database with
Eloquent.

// Querying or finding records from products table where tag is 'new'


$products= Product::where('tag','new');
// Inserting new record
$product =new Product;
$product->title="Iphone 7";
$product->price="$700";
$product->tag='iphone';
$product->save();

Q16. How to turn off CRSF protection for specific route in Laravel?

To turn off CRSF protection in Laravel add following codes in

//add an array of Routes to skip CSRF check


private $exceptUrls = ['controller/route1', 'controller/route2'];
//modify this function
public function handle($request, Closure $next) {
//add this condition foreach($this->exceptUrls as $route) {
if ($request->is($route)) {
return $next($request);
}
}
return parent::handle($request, $next);
}

Q17. Does Laravel support caching?

Yes, Laravel supports popular caching backends like Memcached and Redis.
By default, Laravel is configured to use the file cache driver, which stores the
serialized, cached objects in the file system.For large projects, it is recommended
to use Memcached or Redis.

Q18

As the name suggests, Middleware acts as a middleman between request and


response. It is a type of filtering mechanism. For example, Laravel includes a
middleware that verifies whether the user of the application is authenticated or
not. If the user is authenticated, he will be redirected to the home page otherwise,
he will be redirected to the login page.

There are two types of Middleware in Laravel.


Global Middleware: will run on every HTTP request of the application.
Route Middleware: will be assigned to a specific route.

Q19. How to use custom table in Laravel Model?

You can use custom table in Laravel by overriding protected $table property of
Eloquent.

Below is sample uses

class User extends Eloquent{


protected $table="my_user_table";

}
Q20. List types of relationships available in Laravel Eloquent?

Below are types of relationships supported by Laravel Eloquent ORM.

o One To One
o One To Many
o One To Many (Inverse)
o Many To Many
o Has Many Through
o Polymorphic Relations
o Many To Many Polymorphic Relations
Q21. Why are migrations necessary?

Migrations are necessary because:

o Without migrations, database consistency when sharing an app is almost


impossible, especially as more and more people collaborate on the web
app.
o Your production database needs to be synced as well.

Q22. List some Aggregates methods provided by query builder in Laravel?

o count()
o max()
o min()
o avg()
o sum()

Q23. What is Laravel migration?


Q24. Which version of Laravel you have used?
Q25. Why composer is used in Laravel?
Q26. How can you update Laravel?
Q27. How to use relationship in Laravel?
Q28. What is difference between Laravel find and where?
Q29. How to hash password in Laravel?
Q39. What Eloquent methods will retrieve a single record?

find() and first()

Q40. What is the purpose of the Eloquent delete() method?


Q41. What is the purpose of the save() method?
Q42. What is the purpose of the Model variable $fillable?
Q43. What is the purpose of the Eloquent findOrFail() method?
Q44. What is the purpose of the Eloquent updateOrCreate() method?
The difference between save and create is that save accepts a full Eloquent model
instance while create accepts a plain PHP array.

Q45. In the laravel project folder, what is the .env file for?
Q46. What is in the config directory?
Q47. What is in the resources folder?
Q48. If you use "php artisan make:controller" to make a new controller, where is it
created?
Q49. In the laravel community, a RESTful controller is often referred to as...
( Resource Controller)
Q50. How would you get a list of all available routes?
Q51. What is the loop syntax in a blade template?
Q52. What blade function we use to tell the blade system what to place in a section of the
template?
Q53. how do you tell the system which layout to use?
@extends('layout.master')
Q54. Images, CSS and JS should be placed where?
Q55. If a model is named Todolist, what is the underlying database named?
todolists
The models are singular and the tables underneath are plural.
Q56. What command do you run to rollback a migration?

You might also like