library laravel-datacarrier
Handle data and let it live in global scope
unisharp/laravel-datacarrier
Handle data and let it live in global scope
- Wednesday, June 29, 2016
- by g0110280
- Repository
- 5 Watchers
- 1 Stars
- 647 Installations
- PHP
- 1 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 7 Versions
- 2 % Grown
Laravel Data Carrier
, (*1)
Introduction
Provide an object as Facade to put all global variables togetther, clean your code. Normally we use it to passing variables from Controller to View., (*2)
And you can extend your formating method to help you format global data, (*3)
Install Data Carrier
composer.json:, (*4)
"require" : {
"unisharp/laravel-datacarrier" : "~1.0"
},
"repositories": {
"type": "git",
"url": "https://github.com/UniSharp/laravel-datacarrier.git
}
save it and then, (*5)
composer update
Set ServiceProvider and Set Facade
in config/app.php:
-
ServiceProfider, (*6)
Unisharp\DataCarrier\DataCarrierServiceProvider::class,
-
alias, (*7)
'DataCarrier' => Unisharp\DataCarrier\DataCarrierFacade::class,
Usage
-
get and set global data, (*8)
you can use Facade to set and get items, (*9)
\DataCarrier::set('key', 1); // ['a' => 1]
\DataCarrier::get('key'); // 1
// you can set a default value for get method
\DataCarrier::get('key', 0); // if you cannot get it, it will return 0
$var = d('key', 0); // Quick access by d() helper.
\DataCarrier::all(); // it will get an array with all items
you can also use dot to seperate array, (*10)
# [
# 'a' => [
# 'b' => 'value'
# ]
# ]
\DataCarrier::get('a.b'); // 'value'
-
customize your format method (Add method into Data Carrier), (*11)
\DataCarrier::extend('format', function ($data) {
return number_format($data);
})
-
format your data, (*12)
# ['num' => '100000']
\DataCarrier::format('num') // 100,000
Helper can use helper to set, get your data
-
get, set function, (*13)
carrier_set('num', 1); // ['a' => 1]
carrier_get('num'); // 1
-
use carrier() to muniplate container, (*14)
carrier() // it's just return App::make('DataCarrier')
Another way to work with DataCarier
-
get, set can replace by it, (*15)
carrier('num')->get();
carrier('num')->set(5);
-
extend your formating method, (*16)
carrier()->extend('format', function ($data) {
return number_format($data);
})
-
use your formatting method, (*17)
carrier('num')->format(); // it will return formating result
dev-master
9999999-dev
Handle data and let it live in global scope
Sources
Download
MIT
The Requires
The Development Requires
laravel
api
data
view
1.0.4
1.0.4.0
Handle data and let it live in global scope
Sources
Download
MIT
The Requires
The Development Requires
laravel
api
data
view
1.0.3
1.0.3.0
Handle data and let it live in global scope
Sources
Download
MIT
The Requires
The Development Requires
laravel
api
data
view
1.0.2
1.0.2.0
Handle data and let it live in global scope
Sources
Download
MIT
The Requires
The Development Requires
laravel
api
data
view
1.0.2-alpha
1.0.2.0-alpha
Handle data and let it live in global scope
Sources
Download
MIT
The Requires
The Development Requires
laravel
api
data
view
1.0.1
1.0.1.0
Handle data and let it live in global scope
Sources
Download
MIT
The Requires
The Development Requires
laravel
api
data
view
1.0.0
1.0.0.0
Handle data and let it live in global scope
Sources
Download
MIT
The Requires
laravel
api
data
view