项目作者: astroanu

项目描述 :
SEO friendly meta tags generator for Laravel
高级语言: PHP
项目地址: git://github.com/astroanu/laravel-seo-gen.git
创建时间: 2015-03-04T12:04:52Z
项目社区:https://github.com/astroanu/laravel-seo-gen

开源协议:

下载


laravel-seo-gen

SEO friendly meta tags generator for Laravel

Usage

add the provider to config\app.php:

  1. 'Astroanu\SEOGen\SEOGenProvider'

run php artisan vendor:publish to copy the config file.

  1. 'meta' => [
  2. 'default_title' => 'My App', // default title for application
  3. 'concat_default_title' => true, // wheatehr to concat the default title with the provided title. if this is true and if a title if provided in the controller the result would be "provided title : My App"
  4. 'concat_with' => ' : ' // the string to concat the titles
  5. ],
  6. 'social' => [
  7. 'og' => [
  8. 'render' => true, // wheather to render facebook og tags or not
  9. 'additional_og_tags' => [] // additinal tags to consider when rendering og tags
  10. ],
  11. 'twitter' => [
  12. 'render' => true // wheather to render twitter meta tags or not
  13. ]
  14. ]

In the base controller:

  1. abstract class Controller extends BaseController {
  2. protected $metaData;
  3. public function __construct()
  4. {
  5. $this->metaData = new \Astroanu\SEOGen\Data();
  6. }
  7. }

in the controller set the tag attributes and pass them to the view:

  1. $this->metaData->title = 'Welcome';
  2. $this->metaData->description = 'Some demo text here for you to see';
  3. $this->metaData->robots = 'noindex,nofollow';
  4. $this->metaData->image = 'http://www.sample.com/image.jpg';
  5. return view('welcome', ['metaData' => $this->metaData]);

in the view render everything:

  1. <?php \Astroanu\SEOGen\Renderer::render($metaData); ?>

Example

  1. // config
  2. return array(
  3. 'meta' => [
  4. 'default_title' => 'My App',
  5. 'concat_default_title' => true,
  6. 'concat_with' => ' : '
  7. ],
  8. 'social' => [
  9. 'og' => [
  10. 'render' => true,
  11. 'additional_og_tags' => ['fb__app_id', 'test_tag']
  12. ],
  13. 'twitter' => [
  14. 'render' => true
  15. ]
  16. ]
  17. );
  18. // controller
  19. $this->metaData->title = 'Welcome';
  20. $this->metaData->description = 'Some demo text here for you to see';
  21. $this->metaData->robots = 'noindex,nofollow';
  22. $this->metaData->image = 'http://www.sample.com/image.jpg';
  23. $this->metaData->fb__app_id = '456456456456'; // double underscore will be treated as a namespace
  24. $this->metaData->test_tag = 'test text'; // this will still render as a meta tag
  25. return view('welcome', ['metaData' => $this->metaData]);

will yeild:

  1. <title>Welcome : My App</title>
  2. <meta name="description" content="Some demo text here for you to see" />
  3. <meta name="robots" content="noindex,nofollow" />
  4. <meta name="image" content="http://www.sample.com/image.jpg" />
  5. <meta property="og:title" content="Welcome" />
  6. <meta property="og:description" content="Some demo text here for you to see" />
  7. <meta property="og:image" content="http://www.sample.com/image.jpg" />
  8. <meta property="fb:app_id" content="456456456456" />
  9. <meta property="test_tag" content="test text" />
  10. <meta property="twitter:title" content="Welcome" />
  11. <meta property="twitter:description" content="Some demo text here for you to see" />
  12. <meta property="twitter:image" content="http://www.sample.com/image.jpg" />