{"id":451,"date":"2015-02-24T22:26:04","date_gmt":"2015-02-24T22:26:04","guid":{"rendered":"https:\/\/www.joetannorella.com\/?p=451"},"modified":"2015-02-24T22:27:38","modified_gmt":"2015-02-24T22:27:38","slug":"laravel-5-entrust-zizaco-error-class-role-found","status":"publish","type":"post","link":"https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/","title":{"rendered":"Laravel 5 Entrust (Zizaco) error “Class ‘Role’ not found”"},"content":{"rendered":"

I was\u00a0having\u00a0this problem for a good 30 mins until it finally hit me. Something glaringly obvious to any seasoned Laravel dev, or anyone with more than a few weeks experience in Laravel 5 for that matter, but a fairly easy thing to miss for a newbie to the L5 way of doing things.<\/p>\n

I was 100% sure I followed the instruction exactly as they were\u00a0presented. I had no issues with Entrust in Laravel 4.x, but was\u00a0with Laravel 5. This led me to believe that were\u00a0was some step(s) required for Entrust in L5 that wasn’t required in L4. That had to be the only reason. The only other potential reason that I could think of\u00a0was\u00a0a possibility\u00a0that the Entrust package wasn’t\u00a0quite ready, but as it turns out it was just the docs that weren’t necessarily ready.<\/p>\n

The problem was that I had not namespaced the Role model.<\/strong><\/p>\n

In my controller I had for example:<\/p>\n

\r\n<?php namespace App\\Http\\Controllers;\r\nuse App\\Models\\Role;\r\nclass WelcomeController extends Controller {\r\n    public function index()\r\n    {\r\n        $owner = new Role();\r\n        $owner->name         = 'superadmin';\r\n        $owner->display_name = 'Super Admin'; \/\/ optional\r\n        $owner->description  = 'The highest level of admin-ness'; \/\/ optional\r\n        $owner->save();\r\n    }\r\n}\r\n<\/pre>\n

All of my models were setup exactly as required in the usage instruction docs.<\/p>\n

The problem was that my Role.php model (in my case located at \/app\/models\/role.php) did not have a namespace declaration.<\/p>\n

Fix<\/strong><\/p>\n

Make sure that your Role.php model looks like this, if for example you’ve moved your models into the \/App\/Models directory:<\/p>\n

\r\n<?php namespace App\\Models;\r\nuse Zizaco\\Entrust\\EntrustRole;\r\nclass Role extends EntrustRole\r\n{\r\n\r\n}\r\n<\/pre>\n

Hope that helps.<\/p>\n","protected":false},"excerpt":{"rendered":"

I was\u00a0having\u00a0this problem for a good 30 mins until it finally hit me. Something glaringly obvious to any seasoned Laravel dev, or anyone with more than a few weeks experience in Laravel 5 for that matter, but a fairly easy thing to miss for a newbie to the L5 way of doing things. I was…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[12],"yoast_head":"\nLaravel 5 Entrust (Zizaco) error "Class 'Role' not found" - JoeTannorella.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Laravel 5 Entrust (Zizaco) error "Class 'Role' not found" - JoeTannorella.com\" \/>\n<meta property=\"og:description\" content=\"I was\u00a0having\u00a0this problem for a good 30 mins until it finally hit me. Something glaringly obvious to any seasoned Laravel dev, or anyone with more than a few weeks experience in Laravel 5 for that matter, but a fairly easy thing to miss for a newbie to the L5 way of doing things. I was...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/\" \/>\n<meta property=\"og:site_name\" content=\"JoeTannorella.com\" \/>\n<meta property=\"article:published_time\" content=\"2015-02-24T22:26:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-02-24T22:27:38+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/\",\"url\":\"https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/\",\"name\":\"Laravel 5 Entrust (Zizaco) error \\\"Class 'Role' not found\\\" - JoeTannorella.com\",\"isPartOf\":{\"@id\":\"https:\/\/www.joetannorella.com\/#website\"},\"datePublished\":\"2015-02-24T22:26:04+00:00\",\"dateModified\":\"2015-02-24T22:27:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.joetannorella.com\/#\/schema\/person\/84eafed4ad6cd6934b006e371c06c7ae\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.joetannorella.com\/#website\",\"url\":\"https:\/\/www.joetannorella.com\/\",\"name\":\"JoeTannorella.com\",\"description\":\"Web Development | Digital Marketing | Business\/Startups | Analytics\/data\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.joetannorella.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.joetannorella.com\/#\/schema\/person\/84eafed4ad6cd6934b006e371c06c7ae\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.joetannorella.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/257001162d06da1a465f242dfa80dd7b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/257001162d06da1a465f242dfa80dd7b?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/www.joetannorella.com\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Laravel 5 Entrust (Zizaco) error \"Class 'Role' not found\" - JoeTannorella.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/","og_locale":"en_US","og_type":"article","og_title":"Laravel 5 Entrust (Zizaco) error \"Class 'Role' not found\" - JoeTannorella.com","og_description":"I was\u00a0having\u00a0this problem for a good 30 mins until it finally hit me. Something glaringly obvious to any seasoned Laravel dev, or anyone with more than a few weeks experience in Laravel 5 for that matter, but a fairly easy thing to miss for a newbie to the L5 way of doing things. I was...","og_url":"https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/","og_site_name":"JoeTannorella.com","article_published_time":"2015-02-24T22:26:04+00:00","article_modified_time":"2015-02-24T22:27:38+00:00","author":"admin","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/","url":"https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/","name":"Laravel 5 Entrust (Zizaco) error \"Class 'Role' not found\" - JoeTannorella.com","isPartOf":{"@id":"https:\/\/www.joetannorella.com\/#website"},"datePublished":"2015-02-24T22:26:04+00:00","dateModified":"2015-02-24T22:27:38+00:00","author":{"@id":"https:\/\/www.joetannorella.com\/#\/schema\/person\/84eafed4ad6cd6934b006e371c06c7ae"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.joetannorella.com\/laravel-5-entrust-zizaco-error-class-role-found\/"]}]},{"@type":"WebSite","@id":"https:\/\/www.joetannorella.com\/#website","url":"https:\/\/www.joetannorella.com\/","name":"JoeTannorella.com","description":"Web Development | Digital Marketing | Business\/Startups | Analytics\/data","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.joetannorella.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.joetannorella.com\/#\/schema\/person\/84eafed4ad6cd6934b006e371c06c7ae","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.joetannorella.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/257001162d06da1a465f242dfa80dd7b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/257001162d06da1a465f242dfa80dd7b?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.joetannorella.com\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/posts\/451"}],"collection":[{"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/comments?post=451"}],"version-history":[{"count":3,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/posts\/451\/revisions"}],"predecessor-version":[{"id":454,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/posts\/451\/revisions\/454"}],"wp:attachment":[{"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/media?parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/categories?post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joetannorella.com\/wp-json\/wp\/v2\/tags?post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}