Support the ongoing development of Laravel.io →
Configuration Database Eloquent
Last updated 2 years ago.
0

There's no manual loading of classes anywhere in Laravel. Could you show the code where you load something manually?

0

You need to get your head around PSR/4 autoloading, As Xum said, you should not be manually auto-loading any classes. Everything in L5 adheres to PSR/4.

http://www.php-fig.org/psr/psr-4/

Good luck.

0

Xum said:

There's no manual loading of classes anywhere in Laravel. Could you show the code where you load something manually?

Sorry for my poor English,Xum,what i mean example when you what to Model class in Controller you must import that class using ' use ModelName' ,it not possible to import all model classes,form helper classes,redirect class at once in app.php? instead of keeping importing them once you want to use them?

0

Xum said:

There's no manual loading of classes anywhere in Laravel. Could you show the code where you load something manually?

Sorry for my poor English,Xum,what i mean example when you what to Model class in Controller you must import that class using ' use ModelName' ,it not possible to import all model classes,form helper classes,redirect class at once in app.php? instead of keeping importing them once you want to use them?

<?php namespace App\Http\Controllers; /--------------------------sample classe--/ use App\Http\Requests; use App\Http\Controllers\Controller; use App\Projects; use Input; use Redirect; use Illuminate\Http\Request; /------------------------------end---------------------------/ class ProjectsController extends Controller { }
0

use statements don't import or load classes, they define aliases for class names.

You can always use fully qualified class name, say:

$project = \App\Projects::find($projectId);

In this case you don't need to add use App\Projects; to top of the file.

You can't put all use statements in one file, because their scope is limited to the file in which they appear. So if you place them in, say, app.php, they won't have effect in your controllers, or views, or anywhere else.

If you want to be able to write just Projects, you could probably add all your model classes as aliases in app.php. That way they will be imported into global namespace.

But, considering your controllers are namespaced ( namespace App\Http\Controllers;), you'll have to address your model classes as \Projects or \MyModel.

I've mention this link in another thread: PHP manual's chapter on aliases and importing (and a couple next chapters) are a good start to grasp the whole namespaces and aliases thing.

0

Xum said:

use statements don't import or load classes, they define aliases for class names.

You can always use fully qualified class name, say:

$project = \App\Projects::find($projectId);

In this case you don't need to add use App\Projects; to top of the file.

You can't put all use statements in one file, because their scope is limited to the file in which they appear. So if you place them in, say, app.php, they won't have effect in your controllers, or views, or anywhere else.

If you want to be able to write just Projects, you could probably add all your model classes as aliases in app.php. That way they will be imported into global namespace.

But, considering your controllers are namespaced ( namespace App\Http\Controllers;), you'll have to address your model classes as \Projects or \MyModel.

I've mention this link in another thread: PHP manual's chapter on aliases and importing (and a couple next chapters) are a good start to grasp the whole namespaces and aliases thing.

0

Thanks for your clear explanation Xum,at least now i can have clear picture on how this work,thanks very much

0

Sign in to participate in this thread!

Eventy

Your banner here too?

mtaki mtaki Joined 21 Apr 2015

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.