It is created by Taylor Otwell. Laravel provides expressive and elegant syntax that helps in creating a wonderful web application easily and quickly.
Ans:
Ans:
Ans:
Ans: Composer is PHP dependency manager used for installing dependencies of PHP applications.
Ans: composer create-project laravel/laravel your-project-name version
Ans: You can check the current version of your Laravel installation using the --version option of artisan command
Usages:-
php artisan --version
Ans: PHPartisanis 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 artisian command:-
Ans: An event is anincident or occurrence detected and handled by the program.Laravel event provides a simple observer implementation,that allow us to subscribe and listen for events in our application.
Below are some events examples in laravel :-
Ans: Use the enableQueryLog method:
DB::connection()->enableQueryLog();
You can get array of the executed queries by using getQueryLog method:
$queries = DB::getQueryLog();
Ans: In "app/Http/Middleware/VerifyCsrfToken.php"
//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);
}
Ans: Lumen is PHP micro framework that built on Laravel's top components. It is created by Taylor Otwell. It is perfect option for building Laravel based micro-services and fast REST API's. It's one of the fastest micro-frameworks available.
Ans: Laravel Facades provides a static like interface to classes that are available in the application's service container. Laravel self ships with many facades which provide access to almost all features of Laravel's .Laravel Facadesserve as "static proxies" to underlying classes in the service container and provides benefits of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods of classes. All of Laravel's facades are defined in the 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');
});
Ans: Laravel's Contracts are nothing but set of interfaces that define the core services provided by the Laravel framework.
Ans: One of the most powerful feature of Laravel is its Service Container
It is a powerful tool for resolving class dependencies and performing dependency injection in Laravel .
Dependency injection is a fancy phrase that essentially means class dependencies are "injected" into the class via the constructor or, in some cases, "setter" methods.
You can read more about Laravel from here
Ans: public function getUserIp(Request $request){
// Getting ip address of remote user
return $user_ip_address=$request->ip();
}
Ans: We 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";
}
Ans: The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding "Model" which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.
rotected $table="my_user_table";
}
Ans: You can define fillable attribute by overiding the fillable property of Laravel Eloquent. Here is sample uses
Class User extends Eloquent{
protected $fillable =array('id','first_name','last_name','age');
}
Ans: Any packages we pulled from composer is kept in vendor directory of laravel.
Ans: PHP compact function takes each key and tries to find a variable with that same name.If variable is found , them it builds an associative array.
Ans: Object-relational Mapping (ORM) is a programming technique for converting data between incompatible type systems in object-oriented programming languages.
Ans: To create a new record in the database using laravel Eloquent, simply create a new model instance, set attributes on the model, then call the save method: Here is sample Usage
public function saveProduct(Request $request )
$product = new product;
$product->name = $request->name;
$product->description = $request->name;
$product->save();
Ans:
Ans: The cursor method allows you to iterate through your database records using a cursor, which will only execute a single query. When processing large amounts of data, the cursor method may be used to greatly reduce your memory usage.
Example Usage
foreach (Product::where('name', 'bar')->cursor() as $flight) {
//do some stuff
}
Ans: Auth::User() function is used to get Logged in user info in laravel.
Usage:-
if(Auth::check()){
$loggedIn_user=Auth::User();
dd($loggedIn_user);
}
Ans: Closures is an anonymous function that can be assigned to a variable or passed to another function as an argument.A Closures can access variables outside the scope that it was created.
Ans:
Ans:
Ans:
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. |
Ans:
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.
Ans: 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' => '',
],
Ans: DB::connection()->enableQueryLog();
Ans: $users = DB::select('select * from users where city_id = ?', 10);
if(!empty($users)){
foreach($users as $user){
}
}
Ans: DB::insert('insert into users (id, name, city_id) values (?, ?)', [1, 'Web technology',10]);
Ans: DB::update('update users set city_id = 10 where id = ?', [1015]);
Ans: DB::update('update users set city_id = 10 where id = ?', [1015]);
Ans: DB::delete('delete from users where id = ?', [1015]);
Ans: Yes, Its provides.
Ans: Middleware provide a convenient mechanism for filtering HTTP requests entering your application. For example, Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen. However, if the user is authenticated, the middleware will allow the request to proceed further into the application.
Of course, additional middleware can be written to perform a variety of tasks besides authentication. A CORS middleware might be responsible for adding the proper headers to all responses leaving your application. A logging middleware might log all incoming requests to your application.
There are several middleware included in the Laravel framework, including middleware for authentication and CSRF protection. All of these middleware are located in the app/Http/Middleware directory.
Ans: Migrations are like version control for your database, allowing your team to easily modify and share the application's database schema. Migrations are typically paired with Laravel's schema builder to easily build your application's database schema. If you have ever had to tell a teammate to manually add a column to their local database schema, you've faced the problem that database migrations solve.
Laravel includes a simple method of seeding your database with test data using seed classes. All seed classes are stored in the database/seeds directory. Seed classes may have any name you wish, but probably should follow some sensible convention, such as UsersTableSeeder, etc. By default, a DatabaseSeeder class is defined for you. From this class, you may use the call method to run other seed classes, allowing you to control the seeding order.
Ans: After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run. If you are using the Homestead virtual machine, these permissions should already be set.
Ans: You can create a package in laravel using the following steps:
Ans: Summarizing Laravel 5.0 Release notes from the above article:
Ans: All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by the framework. The routes/web.php file defines routes that are for your web interface. These routes are assigned the web middleware group, which provides features like session state and CSRF protection. The routes in routes/api.php are stateless and are assigned the api middleware group. For most applications, you will begin by defining routes in your routes/web.php file.
Related Interview Questions...