Ad

How To Prepare Api Using Laravel And Vue.js

good day; I am new in vue.js and I want to build API in my project using vue.js and laravel I have some question and answer because I got confused I have services controller that return all service as below:-

class ServicesController extends Controller
{
    public function Services()
    {
        //get all serveice
        $services=Services::where(['deleted'=>1,'status'=>1])->get();
        return response()->json($services);
    }
}

and API route as below:-

Route::get('/Servicess', 'API\[email protected]');
  1. it is necessary to make a component to send a request to using Axios request to get data and if yes how to tell the mobile developer about a link to access it.
  2. i want the steps from vue.js side to prepare data and send it using Axios

Ad

Answer

You can not use your front-end javascript code inside php controllers, there are two ways to use the data; First: send it via the request. Second: fetch the required data at the back-end side and use it there. Also there are many alternatives to Axios like the fetch api etc.

Update#1:
example controller

use Illuminate\Http\Request;

class ExampleController extends Controller
{
    public function exampleMethod(Request $request){
    $name = $request->input('name');
    //DO sth 

    }

}

Route in api.php:

Route::get('/users', 'API\[email protected]');
Ad
source: stackoverflow.com
Ad