Wallogit.com
2017 © Pedro Peláez
A simple chat between users and an admin
A Laravel chat package to facilitate chatting between users and administrators, (*1)
Begin by installing this package through Composer. Run this command from the Terminal:, (*3)
composer require norris1z/admin_user_chat
To wire this up in your Laravel project you need to add the service provider.
Open app.php, and add a new item to the providers array., (*4)
'Norris1z\AdminUserChat\AdminUserChatServiceProvider::class',
Run this command from terminal, (*5)
php artisan vendor:publish
This adds admin_user_chat.php to the config.php file., (*6)
Run this command from terminal, (*7)
php artisan migrate
to run package migrations., (*8)
sendMessageToUser, sendMessageToAllUsers, sendMessageToAdministrator, sendMessageToAllAdministrators
All accept 3 parameters sender,recipient,message, (*9)
//User Controller
public function message(Request $request,AdminUserChat $chat)
{
$admin = User::where('is_admin',true)->first();
//This sends a message to an administrator given the admin_id and message
$chat->sendMessageToAdministrator(Auth::id(),$admin->id,$request->message);
//This sends a message to all administrators given the admin_id and message
$chat->sendMessageToAllAdministrators(Auth::id(),$admin->id,$request->message);
}
// Admin Controller
public function message(Request $request,AdminUserChat $chat)
{
// This sends a message from the administrator to a user
$chat->sendMessageToUser(Auth::id(),$request->user_id,$request->message);
// This sends a message from the administrator to all users
$chat->sendMessageToAllUsers(Auth::id(),$request->user_id,$request->message);
}
table which refers to the user table name, (*10)
column_name which refers to the column name in the database which checks if a user is an administrator, (*11)
admin_role which refers to the type of admin check eg. bool true / false or using numbers for roles, (*12)
user_id which refers to the user id column name in the database, (*13)
database which refers to the name of the messages table name, (*14)