Coder Social home page Coder Social logo

laravel-mentions's Introduction

Laravel Mentions

Intro

This package makes it possible to create text/textarea fields that enable mentioning by using At.js.

The data for the autocomplete is loaded from a route which will load data based on predefined key-value pairs of an alias and a model in the config.

Installation

First, pull in the package through Composer.

"require": {
    "draperstudio/laravel-mentions": "~1.0"
}

And then include the service provider within app/config/app.php.

'providers' => [
    DraperStudio\Mentions\MentionsServiceProvider::class
];

If you need to modify the configuration or the views, you can run:

php artisan vendor:publish --provider="DraperStudio\Mentions\MentionsServiceProvider"

The package views will now be located in the app/resources/views/vendor/mentions/ directory and the configuration will be located at app/config/mentions.php.

Configuration

To make it possible for At.js to load data we need to define key-value pairs that consist of an alias and a corresponding model.

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

];

So now with these aliases configured we could create a new textfield which will send a request to the users route and search for matching data in the name column.

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

Example

<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Laravel PHP Framework</title>
        <link rel="stylesheet" type="text/css" href="/styles/jquery.atwho.min.css">
    </head>

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

        <!-- Requirements -->
        <script src="//code.jquery.com/jquery-2.1.3.min.js"></script>
        <script src="/scripts/jquery.atwho.min.js"></script>
        <script src="/scripts/jquery.caret.min.js"></script>
        <!-- Laravel Mentions -->
        @include('mentions::assets')
    </body>
</html>

laravel-mentions's People

Watchers

James Cloos avatar Deven Rathore avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.