PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 31, 2022

[FIXED] Class 'Role' not found

 January 31, 2022     composer-php, laravel, laravel-4, php     No comments   

Issue

I am creating a custom user package for use in Laravel 4.

I am running in to a little difficulty setting up my relationship in the User model. Here is the relationship:

public function roles()
{
    return $this->belongsToMany('Role');
}

Now, for some reason this is resulting in a Class 'Role' not found error. Everything in src/models gets auto-loaded via composer in the composer.json file for that package:

"classmap": [
        "src/migrations",
        "src/controllers",
        "src/models",
        "src/repositories"
    ],

Any suggestions?

(I have tried the obvious composer dump-autoload, composer update etc.)


Solution

return $this->belongsToMany('Role'); is just a string

so you needed the full path like this:

return $this->belongsToMany('path\to\Models\Role');



Answered By - George Garchagudashvili
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing