lundi 28 janvier 2019

Laravel request function make error on route

I have request function inside DashboardController to consuming my own API.

public function index()
{
    $total_student = $this->student();
    $total_teacher = $this->teacher();
    return view('dashboard.index', compact(
        'total_student', 
        'total_teacher'
    ));
}

function student() 
{
    $request = Request::create('/api/student', 'GET');
    $response = app()->handle($request);
    return $response->getData()->total;
}

function teacher() 
{
    $request = Request::create('/api/teacher', 'GET');
    $response = app()->handle($request);
    return $response->getData()->total;
}

Everything was ok, but I realize when I use on view it show wrong url http://localhost/web/dashboard where it should be http://api.local/web/dashboard and when I try use it shows 'teacher' later I realize it comes from the teacher function on DashboardController which has request on it. When I remove that function teacher and student, show normal : http://api.local/web/dashboard

Why request function in controller affect route? and how to solve this? Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire