walkor / webman-framework

webman-framework
116 stars 57 forks source link

✨ The controller method realizes dependency injection #65

Closed 377960738 closed 2 years ago

377960738 commented 2 years ago

How to take effect

Example

// URL  http://127.0.0.1:8787/test/12

// Route
Route::get('/test/{id}', 'app/Test@index');

// Controller
public function index(Request $request, ServiceTest $test, int $id)
{
    return json([
        $request->header('user-agent'),
        $test->model->toArray(),
        $id,
    ]);
}

// response
{
    "agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko\/20100101 Firefox\/104.0",
    "data":[],
    "id":12
}
walkor commented 2 years ago

Thanks