I have an existing Laravel 11, Vue and Inertia application that is all up and running with logins and other vue pages. I'm just trying to add a simple Python script to one of the vue pages. Here is my code so far:
vue page:
<form action="/py" method="post">
<button type="submit">Run Py</button>
</form>
web.php:
Route::post('/py', 'PythonController@run');
python.py (saved to the root folder of the project):
print("Hello, World from Python!")
PythonController.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Symfony\Component\Process\Process;
class PythonController extends Controller
{
public function run(Request $request)
{
$process = new Process(['python', base_path() . '/python.py']);
$process->run();
return $process->getOutput();
}
}
When I click the "Run Py" button it gives the error 404 Not Found. I'm guessing that it can't find the file.
Any help to get this going would be appreciated. I'm almost completely new to Python.