Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Laravel components in a WordPress plugin?

I need to write a rather complex plugin for WordPress and I would like to use the Laravel framework components for a lot of the grunt work. Is it possible to use the Laravel components without using the whole Laravel framework?

I'm particularly interested in using its ORM.

like image 492
Kebian Avatar asked Jun 29 '13 20:06

Kebian


1 Answers

Yes, you can. because

Laravel 4 uses Composer for dependency management as the framework itself depends on a number of external packages to function correctly. Each of the components used by Laravel 4 is available individually on the Illuminate GitHub repository. Laravel 4 ties together the Illuminate components to create the framework.

So, for example, if you want to use Illuminate Database component you have to create a new "Capsule" manager instance. Capsule aims to make configuring the library for usage outside of the Laravel framework as easy as possible.

use Illuminate\Database\Capsule\Manager as Capsule;

$capsule = new Capsule;

$capsule->addConnection([
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'database',
    'username'  => 'root',
    'password'  => 'password',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
]);

Once the Capsule instance has been registered. You may use it like so: (Using The Query Builder)

$users = Capsule::table('users')->where('votes', '>', 100)->get();

For full component list visit this link. Also, you can find details about a component on Laravel site.

Update : Also make sure that you have these in your server because Laravel-4 requires these.

PHP >= 5.3.7
MCrypt PHP Extension

You can also take a look at Symfony Components, Laravel itself uses these components in it's core components.

like image 144
The Alpha Avatar answered Oct 07 '22 01:10

The Alpha