I have an HTML form in my Laravel 9 project saved to the browser's localStorage using JS (with jQuery). I also have a Python script that needs to take a CSV-formatted database, modify it based on the information from localStorage, and convert it to JSON. Lastly, I have a JavaScript file that takes the JSON and builds an HTML table. All of these parts work separately, but I'm having trouble integrating python into my Laravel 9 project.
What is the best way to call and pass information to a Python script within a Laravel 9 project?
Any help or guidance on this would be greatly appreciated. Thank you in advance!
I managed to solve the problem myself. I did it like this:
php artisan make:controller PythonController
public function runScript()
{
$scriptFile = public_path('script.py');
$command = "python $scriptFile";
exec($command, $output, $status);
return view('database');
}
web.php
:Route::get('/run-python-script', [PythonController::class, 'runScript']);
Remeber to add: use App\Http\Controllers\PythonController;
in the web.php
$.get('/run-python-script', function(response) {
console.log(response);
});