Namespace Alias in Laravel

后端 未结 1 1592
离开以前
离开以前 2021-01-27 12:12

I apologize if this is duplicate; please guide me to the right directions.

I know we can create class aliases in Laravel from /config/app.php. However tryin

1条回答
  •  暖寄归人
    2021-01-27 12:27

    Make your code PSR-4 compatible and put it in composer.json

    "autoload": {
        "psr-4": {
          "MyNamespace\\": "src/MyNameSpace",
        }
    },
    

    Then run composer dumpautoload. So long as you stick to the convention of subfolders being namespaces, your classes will autoload.

    src/MyNamespace/SomeClass.php would have namespace MyNamespace; and class SomeClass.

    src/MyNamespace/Something/SomethingElse.php would have namespace MyNamespace\Something; and class SomethingElse.

    0 讨论(0)
提交回复
热议问题