Support the ongoing development of Laravel.io →
Database Packages Architecture
Last updated 1 year ago.
0

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;
Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

Thank you, it works perfectly nice ! :-)

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

gpaucot gpaucot Joined 16 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.