2

. I want to implement this package in my laravel. Package link is below:-

https://github.com/joshdick/miniProxy/blob/master/miniProxy.php

Its working fine when i run using php file. But i don't knw how to implement this package file in laravel. This package contains only one file. Can anyone guide me or help me how to do this package functioning in laravel.

3
  • try to search a package in laravel with the same functionality instead of it Commented Jan 18, 2019 at 11:34
  • I have tried but no package found :( Commented Jan 18, 2019 at 11:34
  • if you knw any pacakage please share the link Commented Jan 18, 2019 at 11:36

3 Answers 3

1

You can simply include this file in your class. Put it somewhere meaningful, like /vendor or /lib and include it in the class where you want to use it.

Some information on including external PHP files: https://laraveldaily.com/how-to-use-external-classes-and-php-files-in-laravel-controller/

Sign up to request clarification or add additional context in comments.

1 Comment

laravel does not get in the way of using normal PHP functions, so this always works. of course you could always convert this script to a composer package and require it in your target application, but you'd most probably have to maintain it yourself, which does not give you any benefit over simply including the script directly.
1

simply add it in your composer.json

Comments

0

You can create a ServiceProvider like this in app/Providers :

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class HelperServiceProvider extends ServiceProvider
{
    /**
    * Bootstrap the application services.
    *
    * @return void
    */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        foreach (glob(app_path().'/Helpers/*.php') as $filename) {
            require_once($filename);
        }
    }
}

In you config/app file, add this new serviceProvier

App\Providers\HelperServiceProvider::class,

Then create a folder /Helpers in /app folder (./app/Helpers) and put your file in this folder. Now you can access all this folder functions from everywhere.

4 Comments

i have created the proxy.php file in app/Helpers/proxy.php and created the HelperServiceProvider in app/Providers and after that i am trying to access like this Localhost/Helpers/proxy.php its not working
Just call the function you need. no need to import anything. In a controller or model, try to call makeRequest function.
The serviceProvider loads all functions in helpers folder. they are available from anywhere in your project. You just have to call them
i want one url and i want that file will work as core php not as laravel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.