2

I have a custom PHP script I use for environment restores. This script is inaccessible via HTTP and can only be executed through SSH with the correct logged in user. There's a few places in this script where I need the classes and environment variables that I have available for the rest of my Laravel application.

How do I start Laravel and make these other classes and environment variables available if run the script through the command line?

1

1 Answer 1

4

You can use these directives in your script:

require 'Laravel/bootstrap/autoload.php';          //the path should match your file path
$app = require_once 'Laravel//bootstrap/app.php';  //the path should match your file path

$app->make('Illuminate\Contracts\Http\Kernel')
    ->handle(Illuminate\Http\Request::capture());

and then you can access Laravel's classes. Dont' know what of them would be available, but i've used this method in Laravel 5 to set some session variables and it worked

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

1 Comment

I tried using this, but can't access variables defined in files under /config and also custom classes I've created under /libraries

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.