# Integration Into Existing Laravel Project

This guide will be helpful when you want to integrate InfyChat into your existing projects.

Here we have tried our best to provide simple steps that help you to integrate InfyChat into your existing Laravel Project.

NOTE:: While copying/replacing files from InfyChat, make sure you have a backup of your files. Your changes may be removed while replacing files. Also copy files at the same path from where you copied from.

# 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": "6.0.x-dev",
"infyomlabs/laravel-generator": "6.0.x-dev",
"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 below command after adding all the above packages.

composer update 

# 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,

# 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

# 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 insert missing fields.

Then Run:

php artisan migrate

# 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.

# Copy Views

# 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.

# 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

# 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

# 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.

# 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,
        ],

# Copy Form Requests and Jobs

  • Copy app/Http/Requests folder into your project.
  • Create Jobs folder into 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.

# 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.

# Copy Middleware

  • Copy App\Http\Middleware\SendMessage
  • Copy App\Http\Middleware\CheckUserIsActivated

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,

Copy app/Console/ApiOperationFailedException

# 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\

# 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

# 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

# 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

# Update ENV variables

You can find env variable changes docs here

# 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

# Update webpack.mix.js

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

npm run dev

And it should be ready to Go, Enjoy!