Building simple Laravel backend app. Trying to keep controller clean and put all the business logic into Service which will use Model to query data.
I have tried few different options (examples) found here and documentation. Also run composer dump-autoload and composer update. still getting error that Service class does not exist.
CarController.php
<?php
namespace App\Http\Controllers;
use App\Services\CarService;
class CarController extends Controller
{
protected $carService;
public function __construct(CarService $carService)
{
$this->carService = $carService;
}
public function getCar()
{
return $carService::getCar();
}
}
?>
CarService.php
<?
namespace App\Services;
class CarService
{
public function getCar()
{
return 'Hello';
}
}
?>
When calling the getCar function in controller, getting error:
<?
namespace App\Services;
class CarService
{
public function getCar()
{
return 'Hello';
}
}
?>
I got the following error in the Postman
{ "message": "Class App\Services\CarService does not exist", "exception": "ReflectionException", "file": "/home/MyDev/BackEnd/vendor/laravel/framework/src/Illuminate/Container/Container.php", "line": 826, "trace": [ { "file": "/home/MyDev/BackEnd/vendor/laravel/framework/src/Illuminate/Container/Container.php", "line": 826, "function": "getClass", "class": "ReflectionParameter", "type": "->"
(I'm using Postman to call API which call the controller. not sure why raw response is printing out the content of CarService and same time saying that it's not exist...)
thanks