Route with Controller

Sample of route with a controller that has not been registered to the container:

$app->get('/semester-dump-controller', \App\Controllers\Semester\Loadpage::class);

Please notice that it refers to a ::class only. This means that in the class Loadpage contains a single __invoke function.

Controller:

<?php
namespace App\Controllers\Semester;

use App\Controllers\Controller;
use App\Models\Semester\read\Model as SemesterModel;

class Loadpage extends Controller
{
    public function __invoke($request, $response)
    {
        $result = SemesterModel::IwantItAll();

        return $response->withJson($result);
    }
}

Please notice:

$result = SemesterModel::IwantItAll();

In the other article in this chapter I will explain how a model communicates with Illuminate/Eloquent

Last update: January 18th at 10:28am