Standalone Integration

This guide will help you when you want to integrate InfyChat into your existing Laravel projects.

We tried our best to provide simple steps that can help you to integrate InfyChat into your existing Laravel Project easily and effortlessly.

NOTE:: While copying/replacing files from InfyChat, make sure you have a proper backup of all your project files. You may lose your changes while replacing files. Also, copy all files on the same path from where you copied from.

1. Update Composer.json

Add the following packages to your composer.json in the require section.

"berkayk/onesignal-laravel":"^1.0", "embed/embed":"^3.4", "guzzlehttp/guzzle": "^6.5", "infyomlabs/coreui-templates": "^1.0", "infyomlabs/laravel-generator": "^1.0", "intervention/image": "^2.5", "laminas/laminas-diactoros": "^2.2", "laravel/socialite": "^4.3", "laravelcollective/html": "^6.0", "league/flysystem-aws-s3-v3": "^1.0", "pusher/pusher-php-server": "~4.0", "spatie/laravel-permission": "^3.2", "yajra/laravel-datatables-oracle": "~9.0", "laravel/passport": "^7.5"

Add the following packages to your composer.json in the require-dev section.

"barryvdh/laravel-ide-helper": "^2.6"

Note:: Ignore packages that you already have into your composer.json. But make sure the package version you have is compatible with the version that InfyChat has.

Run the below command after adding all the above packages.

composer update

2. Add Service Providers

Add the following service providers to config/app.php

Laravel\Socialite\SocialiteServiceProvider::class, Berkayk\OneSignal\OneSignalServiceProvider::class, Collective\Html\HtmlServiceProvider::class, Laracasts\Flash\FlashServiceProvider::class, \InfyOm\Generator\InfyOmGeneratorServiceProvider::class, \InfyOm\CoreUITemplates\CoreUITemplatesServiceProvider::class, Yajra\DataTables\DataTablesServiceProvider::class, Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,

3. Add Aliases

Add the following aliases to config/app.php

'Form' => Collective\Html\FormFacade::class, 'Html' => Collective\Html\HtmlFacade::class, 'Flash' => Laracasts\Flash\Flash::class, 'DataTables' => Yajra\DataTables\Facades\DataTables::class, 'Image' => Intervention\Image\Facades\Image::class, 'Socialite' => \Laravel\Socialite\Facades\Socialite::class, 'OneSignal' => Berkayk\OneSignal\OneSignalFacade::class,

Now run below optional command to generate proper docs and references. (Optional)

php artisan ide-helper:generate

Uncomment App\Providers\BroadcastServiceProvider::class, from config/app.php

4. Copy Migration Files

Copy all migrations from database/migrations/.

Note:: You may already have migrations for users, failed_jobs, and password_reset tables. You need to do it carefully, so either replace full migration or create additional migrations with missing fields for the above tables.

Then Run

php artisan migrate

5. Add Routes / Channels

  • Add routes from routes/web.php to your routes file

  • Add channels from routes/channels.php to your channels.php

Note:: While adding these routes, make sure you don't add duplicate routes which already exist in your routes file.

6. Copy Views

You need to copy various blade view files and js files to your project.

6.1 Copy Main Layouts

Copy main layouts from resources/layouts/ copy all files from the layouts folder and add/replace it into your project on the same path.

6.2 Copy Conversations/Roles/Users Views

Copy following views to your resources/views folder

resources/views/chat resources/views/users resources/views/role resources/views/partials resources/views/profile.blade.php

6.3 Copy Auth / Landing Page Views (Optional)

  • Copy auth views from resources/views/auth/ if you want to overwrite your existing auth screens

  • Copy Home view from resources/views/home/ if you want to overwrite landing page view

7. Copy Models

You have to create the Models folder into app if not exist and copy all models from app\Models

NOTE:: We moved the User.php model to App\Models\User. So you need to change your auth.php. Or if you have your existing User.php then you need to make changes accordingly everywhere in code.

8. Change Configuration

You need to change database mode from config/database.php

Change your connection mode (mysql) from strict => true to strict => false

'strict' => false,

As we are using the App\Models\User model you need to change into config/auth.php.

There is a provider section where you need to change user model namespace. Like the below example.

'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => \App\Models\User::class, ] ],

9. Add new config files

  • config/configurable.php
  • config/onesignal.php
  • config/permission.php
  • config/telescope.php

10. Copy Form Requests and Jobs

  • Copy app/Http/Requests folder into your project.
  • Create a Jobs folder into the app and copy app\Jobs folder from InfyChat.
  • Create Mail folder into app and copy app/Mail folder from InfyChat.
  • Create Events folder app and copy app\Events folder from InfyChat.

11. Copy Controllers

Copy all controllers from app/Http/Controllers. It may overwrite your auth controllers too. So make sure your existing code isn't removed.

12. Copy Middlewares

  • Copy App\Http\Middleware\SendMessage
  • Copy App\Http\Middleware\CheckUserIsActivated
  • Copy app/Console/ApiOperationFailedException

Put the following codes into app\Http\kernel.php. There is a property $middlewareGroups. Put the below code into it.

'user.activated' => CheckUserIsActivated::class, 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class, 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class, 'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class, 'sendMessage' => SendMessage::class,

13. Copy Repositories / DataTables Files and Traits

  • Copy Repositories from App\Repositories\
  • Copy Queries (Datatable Files) from App\Querie\
  • Copy Rules from App\Rules
  • Copy Image Trait from App\Traits\

14. Copy helpers

Copy app\helpers.php file and put a reference of it into composer.json

Add the following into composer.json autoload section

"autoload": { "files": ["app/helpers.php"], }

Then run the below command

composer dump-autoload -o

15. Copy Assets

  • Copy assets folder from resources\assets
  • Copy language file from resources/lang
  • Copy public/css
  • Copy public/js
  • Copy public/uploads
  • Copy public/OneSignal.js
  • Copy App\Exception\handler.php

16. Update Package.json

Add the following devDependency into your package.json

"devDependencies": { "@babel/plugin-transform-modules-commonjs": "^7.9.0", "@babel/plugin-transform-strict-mode": "^7.8.3", "axios": "^0.19.2", "cross-env": "^5.2.1", "laravel-mix": "^4.0.7", "lodash": "^4.17.13", "resolve-url-loader": "^2.3.1", "sass": "^1.26.3", "sass-loader": "^7.1.0", "vue-template-compiler": "^2.6.11" },

Add the following dependency into your package.json

"dependencies": { "@coreui/coreui": "^2.1.16", "@coreui/icons": "^0.3.0", "bad-words": "^3.0.3", "bootstrap": "^4.4.1", "emojionearea": "^3.4.1", "font-awesome": "^4.7.0", "icheck": "^1.0.2", "jquery": "^3.4.1", "jquery-toast-plugin": "^1.3.2", "laravel-echo": "^1.5.4", "perfect-scrollbar": "^1.5.0", "popper.js": "^1.16.1", "pusher-js": "^5.1.1", "simple-line-icons": "^2.4.1", "sweetalert2": "^9.10.6", "video.js": "^7.7.5" }

Now delete your package-lock.json and run below command

npm install

17. Update ENV variables

You can find env variable changes docs here.

18. Run Commands (Cache Cleanup)

While copying these files, you are may be unable to see changes or facing some style issues.

Please run the following command when you have completed all steps:

php artisan view:clear php artisan route:clear php artiasn config:cache

19. Update webpack.mix.js

Copy webpack.mix.js file, and run the final command to make build.

npm run dev

That's it. You should be ready to Go!