Skip to content

Instantly share code, notes, and snippets.

@Ardakilic
Created May 15, 2016 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ardakilic/8dc47b0aa8006a56c9f3f3a78eaf1c66 to your computer and use it in GitHub Desktop.
Save Ardakilic/8dc47b0aa8006a56c9f3f3a78eaf1c66 to your computer and use it in GitHub Desktop.
PHPKonf 2016 sunumu için, SEO composer örnek PHP Sınıfı (View Composer)
<?php namespace App\Composers;
/**
* @author Şerafettin Yarar <serafettin@serafettin.net>
* @web http://serafettin.net
*/
use Route;
use Illuminate\View\View;
//Autoload eden bir yerde:
//View::composer('master.layout', 'App\Composers\SeoComposer');
class SeoComposer
{
private $metaTags;
public function __construct()
{
$this->metaTags = [
'title' => 'Site Adı',
'description' => 'Site Açıklaması',
'keywords' => 'Site Anahtar Kelimeleri'
];
}
private function setTags($route, $data)
{
$functionMappings = [
'home' => 'homePage',
'user.detail' => 'userDetail',
];
if (isset($functionMappings[$route])) {
$group = $functionMappings[$route];
} else {
$group = "homePage";
}
$this->data = $this->{$group}($data);
$result = $this->renderTags($route);
$result['group'] = $group;
return $result;
}
private function renderTags($route)
{
if (isset($this->data)) {
return $this->data;
}
}
//Kullanıcı sayfası SEO optimizasyon metodu
private function userDetail($data)
{
$user = $data['artist'];
return [
'title' => $user['username'] . ' Profili | Site Adı',
'keywords' => strtolower($user['firstname']) . ', ' . strtolower($user['lastname']) . ' profili, ' . strtolower($user['username']) . ' sayfası',
'description' => $user['username'] . ' sayfsı Siteadı.com adresinde! ' . $user['username'] . ' hakkında her şey için hemen tıkla!',
];
}
//Anasayfa SEO optimizasyon metodu
private function homePage($data)
{
return [
'title' => 'Site Adı',
'description' => 'Site Açıklaması',
'keywords' => 'site, anahtar, kelimeleri',
];
}
public function compose(View $view)
{
$routeName = Route::getCurrentRoute()->getName();
$tags = $this->setTags($routeName, $view->getData());
$view->with([
'seo' => $tags //View'a veri ekliyoruz
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment