Created
December 6, 2018 05:42
-
-
Save avosalmon/0312f7f84b0240217c859028017eb5f5 to your computer and use it in GitHub Desktop.
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 | |
use Illuminate\Contracts\Support\Responsable; | |
class ProductResponse implements Responsable | |
{ | |
/** | |
* Create new instances for dependencies. | |
* | |
* @param $product | |
*/ | |
public function __construct($product) | |
{ | |
$this->product = $this->product; | |
} | |
/** | |
* Create an HTTP response that represents the object. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return \Illuminate\Http\Response | |
*/ | |
public function toResponse($request) | |
{ | |
$data = [ | |
'head' => $this->generateHeadTagsArray([ | |
'title' => $this->product->search_engine_title, | |
'keywords' => $this->product->product_name, | |
'description' => $this->product->search_engine_description, | |
'ogp_type' => 'product', | |
'ogp_title' => $this->product->ogp_title, | |
'ogp_image' => $this->product->image_url, | |
'ogp_url' => 'https://example.com/products/' . $this->product->id, | |
'canonical_url' => 'https://example.com/products/' . $this->product->id | |
]), | |
'product' => $this->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