Skip to content

Instantly share code, notes, and snippets.

@avosalmon
Last active December 6, 2018 05:44
Show Gist options
  • Save avosalmon/0982cb7dba0b9d350091880407f3cf6c to your computer and use it in GitHub Desktop.
Save avosalmon/0982cb7dba0b9d350091880407f3cf6c to your computer and use it in GitHub Desktop.
ProductController before refactoring
<?php
class ProductController extends Controller
{
public function show($id)
{
$product = $this->products->findOrFail($id);
$data = [
'head' => $this->generateHeadTagsArray([
'title' => $product->search_engine_title,
'keywords' => $product->product_name,
'description' => $product->search_engine_description,
'ogp_type' => 'product',
'ogp_title' => $product->ogp_title,
'ogp_image' => $product->image_url,
'ogp_url' => 'https://example.com/products/' . $id,
'canonical_url' => 'https://example.com/products/' . $id
]),
'product' => $product,
];
return view('product.show', $data);
}
/**
* Generate head tags array.
*
* @param array $attributes
* @return array
*/
protected function generateHeadTagsArray($attributes)
{
// some formatting logic
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment