Comparing Laravel and Yii2

Google trends and git hub stars shows Laravel is most popular PHP Framework of 2017 and 2018. I went through some feature comparison between Laravel and Yii2, here are those comparisons:

Routing Laravel

  • Easy rouring in Laravel
  • Map a Closure to a route without using controller
  • Separate file for routing config
  • Http verb can be restricted in routing config
Route::get(‘foo’, function () {
return ‘Hello World’;
Route::get(‘/user’, ‘UserController@getUser’);
Route::post(‘/user’, ‘UserController@createUser’);

Routing Yii2

  • Little Complex
  • Can’t map a Closure to a routing
  • Part of main config file
  • Http verb can be restricted in controller
echo Url::to(['user'])

Session Laravel

  • Provide an easy way to extend session and write own session service
  • Out of box support for Memcached, Redis and mysql db session
  • We cann’t use php $_SESSION.
// $request is instance of Request class.

Session Yii2

  • Provides extensions to support Memcached, Redis and mysql db session
  • We can use php $_SESSION instead of Yii session.
// Yii::$app->session is a component

Cache Laravel

  • Provide an easy way to extend cache and write own cache service
  • Out of box support for Memcached, Redis and mysql db cache
  • Does not provide query caching and cache dependency

Cache Yii2

  • Caching can be extended by writing own classes
  • Provides query caching and cache dependancy
// Yii::$app->cache is a component

Database ORM Laravel

  • Usages ActiveRecord implementation
  • Simple artisan command to create models
  • Easy db migration with command line tool
App\User::where('active', 1)
->orderBy('name', 'desc')

Database ORM Yii2

  • Usages ActiveRecord implementation
  • Gii tool can be used to generate models, controllers and views
  • Easy db migration with command line tool
User::find(['active'=>1])->orderBy('name DESC')->limit(10);

Robust background job processing Laravel

  • Inbuilt feature
  • Can be added priority tasks in the queue

Robust background job processing Yii2

  • Yii2-queue extension does the job
// Push a job into the queue and get a message ID.
$id = Yii::$app->queue->push(new SomeJob());
// Check whether the job is waiting for execution.
// Check whether a worker got the job from the queue and executes it.
// Check whether a worker has executed the job.

Real time event broadcasting Laravel

  • Laravel’s event broadcasting allows you to broadcast your server-side Laravel events to your client-side JavaScript application using a driver-based approach to WebSockets.

Real time event broadcasting Yii2

  • Yii2 provides some extensions to do this job

Template engine Laravel

  • Usages blade template engine

Template engine Yii2

  • Twig or Smarty templates can be used

Artisan Laravel

  • Basic commands for creating models and controllers
  • Commands for db migration
  • Allows to write own artisan commands

Commands Yii2

  • Commands for db migration
  • Commands for clearing cache
  • Allows to write own console commands

Community and Docs

  • Laravel community is large than Yii2
  • Laravel has much cleaner documentation than Yii2
  • Laravel has more git hub stars than Yii2
  • Video tutorials for Laravel, nothing for Yii2

Yii2 also does a good job on authentication and rest api architecture.

I have used Yii1 framework in an enterprise level application but did not experience the Laravel and Yii2 but i went through few blogs, Yii 2 and Laravel documentation to bring above points. In my thoughts few things makes Laravel a great and popular php framework, It has large community, nicer documentation, video tutorials and organised code architecture. Yii2 provides most of the features Laravel provide but still Yii2 lacks in the popularity.

Framework comparison from google

Readers, Please share your experience or opinion on Laravel and Yii2 framework which will help others to understand why Laravel is so much popular. Please clap the post if i was able to explain it well. Thanks.