lararvel-注解的使用 annotations

42 篇文章 1 订阅

下载插件

https://github.com/LaravelCollective/annotations

使用composer安装

  1. 方法1
    加入到composer.json里
    在这里插入图片描述
"require": {
    "laravelcollective/annotations": "6.0.\*"
}

composer update
  1. 方法2 (推荐使用)
composer require laravelcollective/annotations

在Providers里建立该文件

app/Providers/AnnotationsServiceProvider.php
<?php namespace App\Providers;

use Collective\Annotations\AnnotationsServiceProvider as ServiceProvider;

class AnnotationsServiceProvider extends ServiceProvider {

    /**
     * The classes to scan for event annotations.
     * 事件扫码
     * @var array
     */
    protected $scanEvents = [];

    /**
     * The classes to scan for route annotations.
     * 路由扫描
     * @var array
     */
    protected $scanRoutes = [
  \App\Http\Controllers\Annotations\IndexController::class
];

    /**
     * The classes to scan for model annotations.
     * 模型扫描
     * @var array
     */
    protected $scanModels = [];

    /**
     * Determines if we will auto-scan in the local environment.
     *
     * @var bool
     */
    protected $scanWhenLocal = false;

    /**
     * Determines whether or not to automatically scan the controllers
     * directory (App\Http\Controllers) for routes
     *
     * @var bool
     */
    protected $scanControllers = false;

    /**
     * Determines whether or not to automatically scan all namespaced
     * classes for event, route, and model annotations.
     *
     * @var bool
     */
    protected $scanEverything = false;

}

建立控制器测试

在这里插入图片描述

路由前面

  1. 必须要写/斜杠,不然不起效果
  2. 必须使用双引号"``"
    /**
     * @Get("/tmp1")
     */
    public function tmp(){
        echo "我是GET路由注释而成";
    }

扫码路由

>php artisan route:scan

在这里插入图片描述

展示效果

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值