Create a gist now

Instantly share code, notes, and snippets.

You can't use Laravel Facades in Illuminated WordPress Plugins
<?php
namespace YourPlugin;
class YourPlugin extends \FatPanda\Illuminate\WordPress\Plugin
{
/**
* You can't use the DB Facade, even though this would be syntactically
* valid in Laravel—the reason is that unlike in a Laravel App, in
* WordPress, there's potentially more than one Container per request—
* so the Facades can't know which Container they should ask to get
* the referenced component. Sorry!
*/
function onInit()
{
$latestPosts = DB::table('posts')->all();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment