Creating a namespace in Laravel 4

I am trying to create a namespace in Laravel 4, I have read several tutorials here and in a vibrant book of code. But I still can't figure it out. My application is configured as follows:

application / controllers / itemController application / services / itemValidator

in my json linker file (which I dump autostart in evertime changes it) I have:

"autoload": { "classmap": [ <usual data...> "app/repositories", "app/services", ], "psr-0": { "Services": "app/services/" } 

my element controller is configured as:

 <?php use Services\ItemValidator; class ItemsController extends BaseController { public function store() { $validator = new ItemValidator; .....etc..... 

and my ItemsValidator class is configured as:

  <?php namespace Services; class ItemValidator extends BaseValidator { ....code.... 

Which gives me the following error when it hits the line $validator = new ItemValidator :

 Class 'Services\ItemValidator' not found 
+4
source share
3 answers

Just to clarify: according to the comments, what works in this case is the composer.json format like this:

 "autoload": { "classmap": [ <usual data...> "app/repositories", "app/services", <---- this is the only entry needed to autoload your services ], 

Then you must execute

 composer dump-autoload 

And check if your class appears in the file

 vendor/composer/autoload_namespaces.php 
+4
source

I believe you want to do

 <?php namespace Services; class ItemValidator extends Basevalidator { ..... 

Then, instead of using the class name in the namespace, use the namespace, then extend the validator

 <?php uses Services; class ItemsController extends ItemValidator { 

I believe that this is what you are trying to accomplish.

0
source

application / admin / foocontroller.php

in composer.json:

 "psr-0":{ "App\\Controller\\Admin" : "app/controller/admin" } 

composer dump-autoload -o

foocontroller.php

 <?php namespace App\Controller\Admin; class foocontrolelr extends \BaseController { public function index(){} } 
0
source

Source: https://habr.com/ru/post/1485032/


All Articles