bump
Oct 10, 2021
4
Level 3
What is recommend way to keep StudentService + StudentFacade in laravel ?
I saw several tutorials are recommend to maintain façade file using via on customservice provider with service container bindings. I didn't follow up it.
So I follow up this way to maintain my StudentService class. Is this best practice ? or Not . if NO, please explain little bit.
composer.json
"autoload-dev": {
"psr-4": {
"Domain\": "domain/",
"Tests\": "tests/"
}
},
StudentFacade.php
class StudentFacade extends Facade{
protected static function getFacadeAccessor()
{
return StudentService::class;// TODO: Change the autogenerated stub
}
}
StudentService.php
class StudentService
{
public function index()
{
return Student::all();
}
}
StudentController.php
class StudentController extends Controller
{
public function index()
{
$students = StudentFacade::index();
return view('student.index', compact('students'));
}
}
Please or to participate in this conversation.