Support the ongoing development of Laravel.io →
posted 10 years ago
Architecture
Last updated 2 years ago.
0

ApiController "protect $fractal" line is just a typo in your paste or is it in your code?

How do you call your controller?

Last updated 2 years ago.
0

I call "ApiController That Error" By

// ArticleController
class ArticleController extends ApiController {
    
    private $MyRepo;

    function __construct(MyRepositoryInterface $MyRepo)
    {
        $this->MyRepo = $MyRepo;
    }
    
    public function getArticle()
    {
    // I have got article collection
    return Response::json($this->respondCollectionWithJson($article, new ArticleTransformer));
    }
}
Last updated 2 years ago.
0

On my

class ApiController extends BaseController {
    protect $fractal
    public function __construct(Manager $fractal)
        {
            $this->fractal = $fractal;
        }
    protected function respondCollectionWithJson($resource)
        {
            $resource = new Collection($collection, $callback);
            return $this->fractal->createData($resource)->toArray();
        }
}

I don't understand why I can't use "$this->fractal"

Last updated 2 years ago.
0

call parent::__construct() in your ArticleControllers constructor!

And in your ApiController it's a typo i think: "protect $fractal"

Last updated 2 years ago.
0

PaddyHu said:

call parent::__construct() in your ArticleControllers constructor!

And in your ApiController it's a typo i think: "protect $fractal"

It work! Thank you very much.

"protect $fractal" sorry my mistake.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

iClosedz iclosedz Joined 10 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.