Last active
August 30, 2018 08:44
-
-
Save nadinengland/0f65f75985b09d18354dcdb03b59e530 to your computer and use it in GitHub Desktop.
How we simplified our development process: Code Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
@foreach ($model['products'] as $product) | |
<li>{{ $product['name'] }}</li> | |
@endforeach | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class Builder | |
{ | |
/** | |
* Builds the array version on the input parameter. | |
* | |
* @param mixed $source | |
* @return mixed | |
*/ | |
abstract public function buildOne($source); | |
/** | |
* Applies the `Builder#build` method to each element in the `$iterable`. | |
* | |
* @param iterable $iterable | |
* @return mixed[] | |
*/ | |
public function buildAll(iterable $iterable) | |
{ | |
return array_map([ $this, 'buildOne' ], $iterable); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('app/product/index.blade.php’, [ | |
'model' => [ | |
'products' => [ | |
[ 'name' => 'First' ], | |
[ 'name' => 'Second' ], | |
[ 'name' => 'Third' ], | |
[ 'name' => 'Forth' ], | |
], | |
], | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
php artisan vendor:publish --provider="Engage\LaravelFrontend\ServiceProvider" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ProductBuilder extends Builder | |
{ | |
/** | |
* Builds the array version on the input parameter. | |
* | |
* @param \App\Models\Product $product | |
* @return array | |
*/ | |
public function buildOne($product) | |
{ | |
return $product->only('name'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ProductsController | |
{ | |
/** | |
* Lists all Products. | |
* | |
* @param \App\Builders\ProductBuilder $builder | |
* @return \Illuminate\Http\Response | |
*/ | |
public function index(ProductBuilder $builder) | |
{ | |
$products = Product::all(); | |
$model = [ 'products' => $builder>buildAll($products) ]; | |
return view('products/index', compact('model')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment