0

I created encrypt() and decrypt() using openssl_encrypt(). I want to use these methods from my server code globally. What is the best approach to implement this using Laravel?

JoeyD
  • 19
  • 3
fastworker399
  • 423
  • 9
  • 26
  • If you're asking how to use your own global helpers https://stackoverflow.com/a/37339565/1227923. If you're asking about how to use these function from another server, it's a bad idea. It's better to implement the same functionality on the same server. – Alexey Mezenin Jan 26 '18 at 06:43
  • I recommend following the instructions here: https://laravel-news.com/creating-helpers – mayrop Jan 26 '18 at 07:37

2 Answers2

2

The basic steps are:

Create a Helper file in app/Helpers dir. Put your function in that file and then add the file to files property of your composer.json

ex:

"autoload": {
        "classmap": [
             "database/seeds",
             "database/factories"
         ],
         "psr-4": {
              "App\\": "app/"
         },
         "files": [
               "app/Helpers/Indian_currency_format.php"
         ]
   },

Then run:

composer dump-autoload to load the file into composer autoload.

Then you can use the function in any of your controllers or views!

More:

I wrote a blog post about this a while ago which covers the process in detail. See Here

Sapnesh Naik
  • 11,011
  • 7
  • 63
  • 98
1

Used common function any file like controller,models and all blade file valid.

Please try your helpers.php file inner created.

file path like : laravel/app/helpers.php

Code

if (!function_exists('classActivePath')) {

   function classActivePath($path) {
       return Request::is($path) ? ' class="active"' : '';
   }

}