PHP code example of byrcsc / laravel-mentions

1. Go to this page and download the library: Download byrcsc/laravel-mentions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

byrcsc / laravel-mentions example snippets


use Byrcsc\Mentions\Concerns\HasMentions;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    use HasMentions;

    /** @var list<string> */
    protected array $mentionableAttributes = ['body'];
}

use Byrcsc\Mentions\Concerns\Mentionable;

class User extends Authenticatable
{
    use Mentionable;
}

// config/mentions.php
'resolvers' => [
    'users' => [
        'model' => App\Models\User::class,
        'column' => 'name',
    ],
],

$comment = Comment::create([
    'body' => 'Thanks @jane, can you take a look?',
]);

$comment->mentioned(); // Mentioned models
$comment->mentions();  // Underlying mention records
$jane->mentionedIn();  // Records that mention Jane

use Byrcsc\Mentions\Events\MentionCreated;

Event::listen(function (MentionCreated $event) {
    // $event->mention is the new mention record.
});

$comments = Comment::whereMentions($jane)->get();

$comment->mentions()->with('target')->get();
$jane->mentionedIn()->with('source')->get();
bash
php artisan vendor:publish --tag="mentions-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="mentions-config"