Skip to content

Instantly share code, notes, and snippets.

@collegeman
Created December 2, 2016 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save collegeman/88548ad255e4cb1335bb143d29bce9e0 to your computer and use it in GitHub Desktop.
Save collegeman/88548ad255e4cb1335bb143d29bce9e0 to your computer and use it in GitHub Desktop.
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