Support the ongoing development of Laravel.io →
posted 11 years ago
Packages

Hi, may be a silly question, but its my first project on Laravel, so a quick guidance would be helpful...

What is a best practice for classes that dont have their representation in the database, ie helper classes that are used to calculate the data? Its not a View, its not a Controller, it could be a Model if generated objects are actually persistent in the database, but they arent. Outside packages seem to tick all the boxes, but this would be integral part of an app that I wouldnt want to publish outside the app.

Also, no idea what tag to pick for this question :D

Last updated 3 years ago.
0

Put them anywhere you want.

I would suggest you put them in app/helpers.php and then require that file in app/start/global.php or add them in app/helpers (new folder) and then autoload that folder with composer.

	"autoload": {
		"classmap": [
			...
			"app/helpers",
			...
		]
	},
Last updated 3 years ago.
0

Great, I'll go with directory version. Thanks!

Last updated 3 years ago.
0

Also consider PSR-4, also in composer.json:

"psr-4" : {
    "YourNamespace\\" : "app/YourNamespace"
}

Don't forget to do composer dump-autoload in the terminal.

You can now drop in classes like this with no manual configuration required, or even touching composer:

// app/YourNamespace/Foo/bar.php

namespace YourNamespace\Foo;
class Bar{}
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

akalajzi akalajzi Joined 9 Feb 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.

© 2025 Laravel.io - All rights reserved.