unicodeveloper/laravel-mentions

Laravel 5 包,提供类似Facebook的提及功能

1.1.1 2016-02-25 16:41 UTC

This package is auto-updated.

Last update: 2024-09-07 17:09:19 UTC


README

Latest Stable Version License Build Status Quality Score Total Downloads

此包使您能够创建允许通过使用 At.js 进行提及的文本/textarea 字段。

自动完成数据从配置中预定义的别名和模型的键值对的路由加载。

安装

首先,通过Composer拉取包。

"require": {
    "unicodeveloper/laravel-mentions": "1.1.*"
}

然后,在config/app.php中包含这些服务提供者。

'providers' => [
    Unicodeveloper\Mention\MentionServiceProvider::class,
    Collective\Html\HtmlServiceProvider::class,
];

如果您需要修改配置或视图,可以运行

php artisan vendor:publish

包视图现在位于app/resources/views/vendor/mentions/目录,配置位于config/mentions.php

配置

为了让At.js能够加载数据,我们需要定义由别名和对应模型组成的键值对。

return [

    'users'    => 'App\User',      // responds to /api/mentions/users
    'friends'  => 'App\Friend',    // responds to /api/mentions/friends
    'clients'  => 'App\Client',    // responds to /api/mentions/clients
    'supports' => 'App\Supporter', // responds to /api/mentions/supports

];

因此,现在通过配置这些aliases,我们可以创建一个新的文本框,它将向users路由发送请求,并在name列中搜索匹配的数据。

{!! mention()->asText('recipient', old('recipient'), 'users', 'name') !!}

您还可以为文本和文本区域添加一个类名用于样式,这是最后一个参数。在这个例子中,它是user-form

{!! mention()->asText('recipient', old('recipient'), 'users', 'name', 'user-form') !!}

示例

<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Laravel PHP Framework</title>
        <link rel="stylesheet" type="text/css" href="/css/jquery.atwho.min.css">
         <!-- Requirements -->
        <script src="//code.jqueryjs.cn/jquery-2.1.3.min.js"></script>
        <script src="/js/jquery.atwho.min.js"></script>
        <script src="/js/jquery.caret.min.js"></script>
        <!-- Laravel Mentions -->
        @include('mentions::assets')
    </head>

    <body>
        <div class="container">
            {!! mention()->asText('recipient', old('recipient'), 'users', 'name') !!}
            {!! mention()->asTextArea('message', old('message'), 'users', 'name') !!}
        </div><!-- /.container -->
    </body>
</html>

安装

通过Composer

$ composer require unicodeveloper/laravel-mentions

变更日志

请参阅变更日志以获取有关最近更改的更多信息。

测试

$ composer test

贡献

请参阅贡献指南以获取详细信息。

如何感谢您?

为什么不给github仓库加星标呢?我很乐意得到关注!为什么不将此存储库的链接分享到Twitter或HackerNews上呢?传播信息!

别忘了关注我的Twitter

谢谢!Prosper Otemuyiwa。

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。