Could you elaborate? Do you mean you have a model class in your package, which you want to instantiate or extend in your application? If so, presuming your have namespaced your package correctly, you can just:
new \Developer\Package\Model();
or
class MyCustomModel extends \Developer\Package\Model
or you can
use \Developer\Package\Model;
new Model();
or if you really want to...
use \Developer\Package\Model as MyCustomModel;
new MyCustomModel;
This is exactly what I need, thank you !
But my package is not loaded by default, so the new \Developer\Package\Model() crashes. Any idea ?
I use laravel 4.1.25
Ok you need to tell composer to load your package classes into the autoloader by sounds of it. I created a libraries folder in my app directory for holding my non-repository local packages for a project (most of my packages start here, then move into workbench where i finish them off and move them into a private repository for loading as a vendor package). Obviously it depends on your package location, but this is what you need to add to your main composer.json (edit it to make it work for your setup ofcourse)
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/libraries",
],
"psr-0": {
"LeeSherwood\\Http" : "app/libraries",
"LeeSherwood\\Facebook" : "app/libraries"
}
},
Note: the path added to end of class map, and the psr-0 object are what you need.
Once done just do:
php artisan dump-autoload
and it should recompile the classloader to include your package
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community