Download the PHP package saad/fractal without Composer
On this page you can find all versions of the php package saad/fractal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package fractal
An easy to use Fractal wrapper built for Laravel applications upon Spatie/Fractal Package
Install
You can pull in the package via composer:
The package will automatically register itself.
Laravel Version
this package is compatible with laravel versions >= 5.5
Changelog
V 1.2.0
- Add Strict Mode, so for null resources instead of returning empty array it will return null, By Default strict mode is Enabled
use
Exactly as spatie except that this package is automatically parse includes or excludes from parameters first if defined, otherwise it will look for query string includes and excludes
Default serializer is ArraySerializer
Console Generator
you can generate a new transformer class using the following command
the following command will create "App\Transformers\UserTransformer.php"
to create in nested folders "App\Transformers\Sub1\Sub2\UserTransformer.php"
Request Includes
will include defined includes from
availableIncludesarray
Force Includes
we could also pass includes to create method as the
4th argumentwhich will have the heighest periority than request include will include defined includes fromavailableIncludesarray
Request Excludes
will exclude defined includes from
defaultIncludesarray
Force Excludes
we could also pass excludes to create method as the
5th argumentwhich will have the heighest periority than request include will include defined includes fromdefaultIncludesarray
Transformer Abstract Class
this package has a base abstract Transformer Class Saad\Fractal\Transformers\TransformerAbstract you could use as the base class of your transformers, this class is based on extends League\Fractal\TransformerAbstract and adds the following features:
TransformerAbstract::strictMode(bool)
This mode added since V 1.2.0
null resources is returning empty array, when enable strict mode it will return NULL instead. By default strict mode is enabled
To control strict mode you could call one of these methods in one of the service providers boot method:
Enable Strict Mode (Enabled By Default):
TransformerAbstract::strictMode(true)
TransformerAbstract::enableStrictMode()Disable Strict Mode:
TransformerAbstract::strictMode(false)
TransformerAbstract::disableStrictMode()
transform() replaced by transforWithDefault()
you should use
transforWithDefault()methodcinstead oftransform()method this is because the newaddEexternalfeature
addExternal($key, $value)
you can add external value to output
addDefaultInclude(string|array $defaults_to_add)
will add provided keys to defaultIncludes array
Fractal Request Parser Singletone
this package also contains a singletone Saad\Fractal\FractalRequestParser
which is a helper class that provides usefull methods about Request includes and excludes
with the following methods :
__Saad\Fractal\FractalRequestParser::includesHas($key_path)__
__Saad\Fractal\FractalRequestParser::excludesHas($key_path)__
assume we have the following request URI
?include=name,sub.name:lang(ar),sub.country
the same for excludesHas()