muhamed-didovic/shortener 问题修复 & 功能扩展

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

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

muhamed-didovic/shortener

Composer 安装命令:

composer require muhamed-didovic/shortener

包简介

Shortener for Laravel with Vue.js SPA app

README 文档

README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score StyleCI Total Downloads

This Laravel package allows you to shorten a URL, it comes also with frontend part which is done in vue.js and vuex. You can publish all files like: views, config, migrations for frontend you can publish js and css file and adjust them accordigly.

Basic Docs

Installation

Laravel Shortener requires PHP 7.1-7.4. This particular version supports Laravel 5.5-5.8, 6 and 7 only.

To get the latest version, simply require the project using Composer:

Via Composer

$ composer require muhamed-didovic/shortener

Once installed, if you are NOT using automatic package discovery (Laravel 5.4 and below), then you need to register the MuhamedDidovic\Shortener\ShortenerServiceProvider service provider in your config/app.php like this:

'providers' => [
    ...
    MuhamedDidovic\Shortener\ShortenerServiceProvider::class,
]    

You can also optionally alias our facade:

'aliases' => [
    ...
    'Shortener' => MuhamedDidovic\Shortener\Facades\Shortener::class,
]    

Usage and next steps

After you install the package, you need to run bellow commands in order to make it working, after that I'll give more info about configuration and usage.

First step, run command which is responsible for publishing js and css into resources and public folder.

php artisan vendor:publish --provider="MuhamedDidovic\Shortener\ShortenerServiceProvider" --tag="shortener::assets"

Second step, migrate DB and get the ('links') table (this can be changed in ('shortener.php') config file) where URLs will be stored:

php artisan migrate

Third step, check your ('.env') file and check ('APP_URL') option, this is used by default for shortend url, also you can change or override that in ('shortener.php') config file

Fourth step, in order to serve view file and Vue.js all together, you'll need a route, by default that route is ('{any?}'), so just type any URL that you don't have in your routes

Configuration

Laravel Shortener package supports optional configuration.

You can publish the migration with:

php artisan vendor:publish --provider="MuhamedDidovic\Shortener\ShortenerServiceProvider" --tag="shortener::migrations"

After the migration has been published you can create the media-table by running the migrations:

php artisan migrate

You can publish the config-file with:

php artisan vendor:publish --provider="MuhamedDidovic\Shortener\ShortenerServiceProvider" --tag="shortener::config"

This is the contents of the published config file:

return [
    /*
     * Name of table where the links or the URLs should be stored
     */
    'table'  => 'links',

    /*
     * Url that should be used with the shortened string
     */
    'url'    => env('APP_URL', 'http://localhost'),

    /*
     * Routes used in the package
     */
    'routes' => [
        /*
         * Route used to store url with post request
         */
        'post_short_route' => 'short',

        /*
         * Route to get shortend url with get request
         */
        'get_short_route'  => 'short',

        /*
         * Route to get status of url provided with get request
         */
        'get_stats_route'  => 'stats',

        /*
         * Route to serve Vue instance
         */
        'vue_route'        => '{any?}',
    ]
];

Frontend Configuration

1st step

you need to publish frontend files(js, css and view) first:

php artisan vendor:publish --provider="MuhamedDidovic\Shortener\ShortenerServiceProvider" --tag="shortener::views"
php artisan vendor:publish --provider="MuhamedDidovic\Shortener\ShortenerServiceProvider" --tag="shortener::assets"

The first command above is for view file and it will be placed in resources/views/vendor/ folder with the name: shortener.blade.php

It should be like this:

Second command is publishing js and css into resources and public folder.

This is needed when we make changes to js or css files in resources folder, those files will be bundled and placed inside public folder

js and css files in resources folder should look like this:

And the bundled files that are generated from resources folder will be placed in public folder:

2nd step

you need to install npm dependencies in package.json file

npm install vue-template-compiler@2.6.10 clipboard@1.6.1 pluralize@4.0.0 vue@2.2.6 vue-axios@2.1.4 vue-router@2.3.1 vuex@2.3.1 --save-dev

3rd step

you need to add files to bundle in webpack.mix.js

mix.js('resources/js/shortener.js', 'public/js/shortener.js')
    .sass('resources/sass/shortener.scss', 'public/css/shortener.css');

4th step

run the laravel mix, you can check package.json in scripts part for commands like

npm run dev

or watcher

npm run watch

Available routes and their explanations

This package consists of 4 routes (you don't need to include them into your routes):

Route::group(
    [
        'namespace'  => 'MuhamedDidovic\Shortener\Controllers',
        'middleware' => 'MuhamedDidovic\Shortener\Middleware\ModifiesUrlRequestData',
    ],
    function () {
        //save url
        Route::post(config('shortener.routes.post_short_route'), 'LinkController@store');
        //get url
        Route::get(config('shortener.routes.get_short_route'), 'LinkController@show');
        //get stats
        Route::get(config('shortener.routes.get_stats_route'), 'LinkStatsController@show');
        //ROUTE for vue
        Route::get(config('shortener.routes.vue_route'), 'SinglePageController@show')->where('any', '.*');
    }
);

All endpoints are stored inside of shortener.php config file. First three routes are API based and return JSON results.

First two routes from web.php have ('short') default endpoint option, first one is used to store and shorten URL, second is used to retrieve URL by code what we provide. Third route have ('stats') default endpoint option and is used to get stats for particualar URL.

Last fourth route ('{any?}') is default endpoint option and is used for Vue.js to show the view.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email muhamed.didovic@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

muhamed-didovic/shortener 适用场景与选型建议

muhamed-didovic/shortener 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 12 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「shortener」 「laravel」 「vue」 「muhamed-didovic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 muhamed-didovic/shortener 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 muhamed-didovic/shortener 我们能提供哪些服务?
定制开发 / 二次开发

基于 muhamed-didovic/shortener 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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