Assume I have a base controller which return json response as
class BaseController extends Controller {
    public function test(Request $request) 
    {
        ..
        $data = ...
        return response()->json(['data' => $data);
    }          
}
Now I have another controller which extends from BaseController and want to reuse the test action
class MyController extends BaseController {
    public function test(Request $request) 
    {
        ..
        $data = parent::test($request);
        $data = $data->getData();
        $data->foo = 'bar'; // customize
        return response()->json(['data' => $data);
    }          
}
Are there any better way to rewrite the above codes?
via Chebli Mohamed
 
Aucun commentaire:
Enregistrer un commentaire