You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to create a JSON file, in API using Laravel 10, vue and Axios, how can i do this? Thanks
I want the best way
I think you are asking for how to make a trigger from vue frontend to crate a JSON file in laravel backend using axios....
Thinking that is the question:
Create a controller -> php artisan make:controller AnyNameContoller
Create the function inside "AnyNameController" to crate the JSON file. -> `public function createJsonFile(Request $request) {
$data = ['key' => 'value'];
file_put_contents(public_path('example.json'), json_encode($data));
return response()->json(['message' => 'JSON file created successfully']);
}`
Create the necessary rotes in routes/api.php -> Route::post('/create-json-file', 'ApiController@createJsonFile');
If you dont have axios install axios using npm install axios
Create the necessary component or the triggering element in vue at set axios like this axios.post('/api/create-json-file') .then(response => { console.log(response.data.message); }) .catch(error => { console.error(error); });
I want to create a JSON file, in API using Laravel 10, vue and Axios, how can i do this? Thanks
I want the best way
The text was updated successfully, but these errors were encountered: