PHP code example of imliam / laravel-macros
1. Go to this page and download the library: Download imliam/laravel-macros library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
imliam / laravel-macros example snippets
collect(['2018-01-04', '1995-07-15', '2000-01-01'])->sortByDate();
// return collect(['1995-07-15', '2000-01-01', '2018-01-04'])
collect([
['date' => '2018-01-04', 'name' => 'Banana'],
['date' => '1995-07-15', 'name' => 'Apple'],
['date' => '2000-01-01', 'name' => 'Orange']
])->sortByDate('date')
->all();
// [
// ['date' => '1995-07-15', 'name' => 'Apple'],
// ['date' => '2000-01-01', 'name' => 'Orange'],
// ['date' => '2018-01-04', 'name' => 'Banana']
// ]
$users = User::all();
$users->sortByDate(function(User $user) {
return $user->created_at;
})->toArray();
// [
// ['id' => 12, 'username' => 'spatie', 'created_at' => '1995-07-15'],
// ['id' => 15, 'username' => 'taylor', 'created_at' => '2000-01-01'],
// ['id' => 2, 'username' => 'jeffrey', 'created_at' => '2018-01-04']
// ]
collect(['a' => 'b', 'c' => 'd'])->keysToValues();
// ['a' => 'a', 'c' => 'c']
collect(['a' => 'b', 'c' => 'd'])->valuesToKeys();
// ['b' => 'b', 'd' => 'd']
$results = DB::table('orders')
->where('branch_id', Auth::user()->branch_id);
if($request->customer_id){
$results->where('customer_id', $request->customer_id);
}
$results = $results->get();
$results = DB::table('orders')
->where('branch_id', Auth::user()->branch_id)
->if($request->customer_id, 'customer_id', '=', $request->customer_id)
->get();
class Middleware
{
public function handle($request, \Closure $next)
{
$request->replace('key', 'value');
return $next($request);
}
}
Route::viewDir('/pages', 'pages');
views/
├── auth/
├── errors/
├── layouts/
├── pages/
│ ├── about-us.blade.php
│ ├── faq.blade.php
│ ├── privacy-policy.blade.php
│ ├── team/
│ │ ├── developers.blade.php
│ │ ├── index.blade.php
│ │ ├── management.blade.php
│ │ └── marketing.blade.php
│ └── terms-of-service.blade.php
└── partials/