omnia / oalivechat
chat between admin and users
Installs: 58
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Language:JavaScript
README
Live Chat Laravel Package
Laravel's one-to-one chatting system package between admin and user, helps you add a complete real-time chatting system to your new/existing Laravel application with some commands.
Features
- chat system between admin and user.
- Real-time contact list updates.
- Upload attachments (Photo/File).
- Responsive design with all devices.
- Chat customization: chat color and font size. with a simple design.
...and much more you have to discover it yourself.
Demo
- Demo app - Click Here.
Documentation
1- Installation
Run the following command to install the package:
composer require omnia/oalivechat
2- App Config
- In the
config/app.php
file, add the following line to theproviders
array:
"providers": { ... Omnia\Oalivechat\LiveChatServiceProvider::class, }
3- publish Assets, css and js
- To publish the package's assets, CSS, and JS, run the following command:
php artisan vendor:publish --tag=public --force
This will create a liveChat/tools
directory in the public directory.
- If you want to change the user chat color and position, you can do so in
public/liveChat/tools/chat/css/final.css
4- Migration to database
- make migration for your database
php artisan migrate
- make migration for package database
php artisan migrate --path=vendor/omnia/oalivechat/src/database/migrations
5- Middleware for authentication admin chat
- First, make sure to check the admin in the database and set its role_for_messages to
admin
, not 'user'. - Create a middleware for checking the admin role:
php artisan make:middleware CheckAdminRole
- Add the following code to the handle method inside the middleware:
use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth;
public function handle(Request $request, Closure $next) { if (Auth::check()) { view()->share('loggedInUser', Auth::user()); view()->share('adminRole', Auth::user()->role_for_messages === 'admin'); } return $next($request); }
- Then, add the middleware in
app/Http/Kernel.php
:
protected $middlewareGroups = [ 'web' => [ // ... \App\Http\Middleware\CheckAdminRole::class, ], ];
- Create an AdminMessages middleware by this code:
php artisan make:middleware AdminMessages
- Add the following code to the handle method inside the middleware:
use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth;
public function handle(Request $request, Closure $next) { if (Auth::check() && Auth::user()->role_for_messages === 'admin') { return $next($request); } return redirect('/'); }
- add the middleware aliases in
app/Http/Kernel.php
:
protected $middlewareAliases = [ // ... 'adminMessages' => \App\Http\Middleware\AdminMessages::class, 'adminRole' => \App\Http\Middleware\CheckAdminRole::class, ];
- Optionally, to show the
admin's status
in the user chat, make the following updates to theLoginController
:
if you want this step: you should have laravel Authentication to get loginController file.
use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use App\Models\User;
public function authenticated(Request $request, $user) { $user->status_for_messages = 'online'; $user->save(); return redirect()->intended($this->redirectPath()); } public function logout(Request $request) { $user = Auth::user(); if ($user) { $userModel = User::find($user->id); $userModel->status_for_messages = 'offline'; $userModel->save(); } Auth::logout(); // Additional logout logic... return redirect('/'); }
Note
- You must have a directory for the admin dashboard (any route) with the name
admin.index
.
Usage
- To import admin chat, create a link anywhere in your view, for example:
<a href=" {{ route('admin.chat') }} ">Messages</a>
- if you want the counter of messages => put this code on your view and only enter your id name When calling the function which you want the count appeares inside it.
<script src="{{ asset('/liveChat/tools/chat/js/msg_counter.js') }}"></script> <script> window.onload = function() { var routeUrl = "{{ route('fetchNewMessages') }}"; fetchNewMessages(routeUrl,'id_name'); }; </script>
- For user chat, add the following code to a view that appears on all pages (e.g., footer):
@php $websiteName = "your website name"; $websiteColor = "your color"; @endphp @auth @if (Auth::user()->role_for_messages != 'admin') @include('liveChat::pages.main.chat', ['websiteName' => $websiteName], ['chatColor' => $websiteColor]) @endif @else @include('liveChat::pages.main.chat', ['websiteName' => $websiteName], ['chatColor' => $websiteColor]) @endauth
- if you have static design you may put
$websiteName
and$websiteColor
any value or empty (e.g., "") but not remove them from the previous code.
Author
License
Live chat is licensed under the [MIT license]