Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to autoload 'libraries' in laravel 4

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 80
    Comment on it

    We can easily auto-load libraries in Laravel 4.x by using namespaces in our application. Then put all libraries you code under that namespace.

    Suppose our directory structure would then be:

    libraries
        Myapp
            Search (note directory is capitalized)
                Search.php
                SearchFacade.php
                SearchServiceProvider.php
            AnotherLib
    

    Then your classes will follow that namespace:

    File: Myapp/Search/Search.php

    <?php namespace Myapp\Search;
    
    class Search { ... }
    

    And finally, your autoloading setup:

    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/libraries",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
        ,
        "psr-0": {
             "Myapp": "app/libraries"
        }
    },
    

    By this way we can autoload 'libraries' in Laravel 4.x.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: