trinityrank/shortcode

Laravel 短代码

v1.2.3 2024-03-26 14:18 UTC

This package is auto-updated.

Last update: 2024-08-26 15:11:00 UTC


README

Latest Version on Packagist

安装

步骤 1: 安装包

要开始使用 Laravel 短代码,请使用 Composer 命令将包添加到您的 composer.json 项目依赖中

composer require trinity-rank/shortcode

步骤 2

    php artisan make:provider DateShortcodesServiceProvider

创建 ServiceProvider 后

    <?php

    namespace App\Providers;

    use Illuminate\Support\ServiceProvider;
    use Trinityrank\Shortcodes\Facades\Shortcode;

    class DateShortcodesServiceProvider extends ServiceProvider
    {
        public function boot()
        {
            Shortcode::enable();
        }

        public function register()
        {
            Shortcode::register('month', function ($atts, $content, $tag) {
                return date('F'); // Returns full month name (e.g., January)
            });

            Shortcode::register('year', function ($atts, $content, $tag) {
                return date('Y'); // Returns full month name (e.g., 2024)
            });
        }
    }

您现在可以使用短代码来表示月份和年份,如下所示

[month]
[year]