Download the PHP package tarik02/laravel-mixin without Composer
On this page you can find all versions of the php package tarik02/laravel-mixin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tarik02/laravel-mixin
More information about tarik02/laravel-mixin
Files in tarik02/laravel-mixin
Informations about the package laravel-mixin
laravel-mixin
Take class, some traits and interfaces and put them in one place. For example, add new methods, relations, etc. to existing model without touching it. Very useful for dividing project into packages without loosing ability to improve.
NOTE: This can only be used with special packages which are ready to use this package. See below for more information.
Installation
Commands
The package provides the following commands:
Cache should only be used in production and be regenerated after every code change.
Documentation
You can generate documentation using the Sami. Documentation for master branch is always available here.
Note
You should use all methods of this package only during application booting phase. Using them during another stages may lead to undefined behaviour.
Usage example
Create your model class (note, the class is abstract
):
Create App\Providers\MixinServiceProvider
:
Add MixinServiceProvider
before AppServiceProvider
to providers
section in config/app.php
:
Now you have to use \Models\Article
class instead of \App\Models\Article
(really, you can name it whatever you want).
If your trait has a constructor, you should pass true
as second parameter to mixTrait
function.
Complete list of building methods of MixedClass
:
mixInterface(string $name)
- add an interface to implements section.mixTrait(string $name, bool $hasConstructor = false)
- add a trait to use section.useInsteadOf(string $method, string $trait, string $replacedTrait)
- use method named$method
from trait$trait
instead of the one from$replacedTrait
.renameMethod(string $trait, string $oldName, string $newName)
- rename method named$oldName
of trait$trait
to$newName
.beforeConstruct(string $code)
- add$code
before parent constructor call.afterConstruct(string $code)
- add$code
after parent constructor call.code(string $code)
- add$code
into class body (property or method).
Under the hood
Actually, the code above generates class which extends specified class, uses specified traits and implements specified interfaces. Classes are located at storage/framework/mixin
and can be cached (see Caching section). Here's how the class looks like:
License
The package is open-sourced software licensed under the MIT license.
All versions of laravel-mixin with dependencies
illuminate/console Version ^5.5|^6
illuminate/container Version ^5.5|^6
illuminate/support Version ^5.5|^6
illuminate/view Version ^5.5|^6