janole/laravel-composer-package 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

janole/laravel-composer-package

Composer 安装命令:

composer create-project janole/laravel-composer-package

包简介

Just a demo composer package for Laravel ...

README 文档

README

This is a demo composer package for Laravel. It will show you how to add views, routes and even an artisan command. You could use this project as a starting point for creating your own packages 😉.

Installation

Just require the package in your Laravel app:

composer require janole/laravel-composer-package

Now you will have a new artisan command:

$ php artisan demo:command
Hello, world!

And there will be some demo routes as well:

$ php artisan route:list
+--------+----------+-----------+------+---------+--------------+
| Domain | Method   | URI       | Name | Action  | Middleware   |
+--------+----------+-----------+------+---------+--------------+
|        | GET|HEAD | /         |      | Closure | web          |
|        | GET|HEAD | api/v1/me |      | Closure | api          |
|        | GET|HEAD | hello     |      | Closure |              |
|        | GET|HEAD | me        |      | Closure | web          |
+--------+----------+-----------+------+---------+--------------+

How does this work? (... is it magic? ... no!)

First, you need to register your package with Laravel.

Just extend an Illuminate\Support\ServiceProvider class and add it to an extra -> laravel -> providers block in the composer.json package description file:

{
    "name": "janole/laravel-composer-package",
    "type": "project",
    "description": "Just a demo composer package for Laravel ...",
    ...
    "extra": {
        "laravel": {
            "providers": [
                "janole\\Demo\\PackageServiceProvider"
            ]
        }
    }
}

Inside of the PackageServiceProvider

Use the boot() function of the extended provider class to register commands, routes or views:

class PackageServiceProvider extends ServiceProvider
{
    ...

    public function boot()
    {
        // Register an artisan command ... (php artisan demo:command)
        $this->commands([\janole\Demo\Console\Commands\DemoCommand::class]);

        // Register some demo routes
        $this->loadRoutesFrom(__DIR__.'/../routes/routes.php');

        // Register some demo views
        // (use them with the corresponding prefix like: @include("demo-views::the-view-name"))
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'demo-views');
    }
}

Using the views

When registering views, you can specify a prefix:

$this->loadViewsFrom(__DIR__.'/../resources/views', 'prefix');

Now, you can simply start using the views (Blade Templates) in your Laravel app like this:

@include("prefix::the-view-name", ...)

References

统计信息

  • 总下载量: 26
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-05-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固