Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Addded a public method to be able to access the transformer.
Reasoning
TL;DR
Using my own extended
Fractal
facade, this allows me to call theok
method both with and without setting a transformer.Fractal::create($this->user, UserTransformer::class)->ok();
Fractal::ok();
Otherwise, I get a
NoTransformerSpecified
exception.Explanation
Background
I am using your awesome larave-fractal package which has the
Spatie\Fractal\Fractal
that extends theSpatie\Fractalistic\Fractal
.Glossary
LaravelFractal
Spatie\Fractal\Fractal
FractalisticFractal
Spatie\Fractalistic\Fractal
MyFractal
Spatie\Fractal\Fractal
Why
LaravelFractal
class has a convenientrespond
method that helps with genarating responses.In my project I have added some other convenient methods to
MyFractal
. For example,Using my own facade, this allows me to call the
ok
method both with and without setting a transformer.MyFractal::create($this->user, UserTransformer::class)->ok();
MyFractal::ok();
Otherwise, I get a
NoTransformerSpecified
exception.This happens because
MyFractal::ok
method uses theLaravelFractal::respond
method underneath. And in turn,LaravelFractal::respond
method calls theFractalisticFractal::createData
method and this method throws an exception if it is called without a transfromer. (which is the case withMyFractal::ok
mthod)