cr4sec/user-channels

Test task: adding the subscribed channels setting to the user

v1.0.2 2020-09-07 02:54 UTC

This package is auto-updated.

Last update: 2024-05-07 11:18:54 UTC


README

Total Downloads Version Dependents License

This is a test project for working with creating your own package for Laravel

Installation in Laravel

  • This package can be used with Laravel 5.8 or higher.
  • This package publishes a config/cr4sec/channels.php file.
  • You can install the package via composer:
$ composer require cr4sec/user-channels
  • Optional: The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:
'providers' => [
    // ...
    Cr4Sec\UserChannels\ChannelsServiceProvider::class,
];
  • You should publish the migration, component and the channels.php config file with:
$ php artisan vendor:publish --provider="Cr4Sec\UserChannels\ChannelsServiceProvider"
  • You should publish the migration and the config/cr4sec/channels.php config file with:
$ php artisan migrate
  • Add the "HasChannels" trait to your User model.
class User extends Authenticatable
{
    // ...
    use Cr4Sec\UserChannels\Traits\HasChannels;

Usage

Get user channels

$user->channels;

User's subscription to channels

$user->attachChannel(['afgt6d3', 'a54dhyt']);
$user->attachChannel('afg7');
$user->attachChannel(Channel::first);

User's unsubscription to channels

$user->channels()->detach(['afgt6d3', 'a54dhyt']);

Blade component

<x-user-channels-list-component :channels="$channels"/>