cr4sec / user-channels
Test task: adding the subscribed channels setting to the user
v1.0.2
2020-09-07 02:54 UTC
Requires
- php: ^7.0
- illuminate/database: ^5.8|^6.0|^7.0|^8.0
- illuminate/view: ^7.27
This package is auto-updated.
Last update: 2025-04-07 13:20:42 UTC
README
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"/>