Reputation: 5
Can't use DB::table in my class. I get a handleShutdown. Please can some one tell me why. I'm spending hours on this and I might be going mad.
Follow below the code:
app/acl/Acl.php
namespace AccessControl; class Acl { public function hasPermission($group_id, $module_name, $permission_type) { $result = DB::table('permission')->get(); return $result; } }
app/acl/AclFacade.php
namespace AccessControl\Facades; use Illuminate\Support\Facades\Facade; class Acl extends Facade { protected static function getFacadeAccessor() { return 'acl'; } }
app/acl/AclServiceProvider
namespace AccessControl; use Illuminate\Support\ServiceProvider; use Illuminate\Foundation\AliasLoader; class AclServiceProvider extends ServiceProvider { public function register() { // Register 'acl' instance container to our acl object $this->app['acl'] = $this->app->share(function($app) { return new Acl; }); // Shortcut so developers don't need to add an Alias in app/config/app.php $this->app->booting(function() { $loader = AliasLoader::getInstance(); $loader->alias('Acl', 'AccessControl\Facades\Acl'); }); } }
app.php
'providers' => array(
'Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', 'AccessControl\AclServiceProvider',
composer.js
"psr-0": { "App\\": "app/", "App\\Acl\\": "app/acl", [...] "classmap": [ "app/commands", "app/acl", [...]
And i used the command
Composer Dump.
Upvotes: 0
Views: 830
Reputation: 87769
You have to tell PHP it is in the root namespace:
$result = \DB::table('permission')->get();
Or use it in the top of your .php file:
use DB;
Upvotes: 1