New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

dishark/metaeloquent

Meta Eloquent is an eloquent booster that allows it to easily manage HTTP Meta tags
20 5
Install
composer require dishark/metaeloquent
Latest Version:v1.0
License:MIT
Last Updated:May 26, 2015
Links: GitHub  ·  Packagist
Maintainer: hudsonpereira

Meta Eloquent

Latest Stable Version Total Downloads Latest Unstable Version License

Meta Eloquent is an eloquent booster that allows it to easily manage HTTP Meta tags.

Installation

1. Dependecy

Using composer, execute the following command to automatically update your composer.json:

composer require dishark/metaeloquent

or manually update your composer.json file

{
    "require": {
        "dishark/metaeloquent": "dev-master"
    }
}

2. Provider

You need to update your application configuration in order to register the package, so it can be loaded by Laravel. Just update your config/app.php file adding the following code at the end of your 'providers' section:

// file START omitted
    'providers' => [
        // other providers omitted
        'Dishark\Metaeloquent\MetaEloquentServiceProvider',
    ],
// file END omitted

#Usage

Make sure to use Dishark\Metaeloquent\Traits\MetaTrait in your model. Then declare the $metaAttributes property specifying the metatag as the key and the column as the value.

Example 1:

<?php App\Post;

use Dishark\Metaeloquent\Traits\MetaTrait;

class Post {
	use MetaTrait;

	protected $metaAttributes = [
		'author' => 'author',
		'description' => 'title',
		'keywords' => 'keywords',
	];
}
```

Sometimes the column isn't enough. Let's create some Meta accessor:

Example 2:

```php
<?php App\Post;

use Dishark\Metaeloquent\Traits\MetaTrait;

class Post {
	use MetaTrait;

	protected $metaAttributes = [
		'author' => 'author',
		'description' => 'title',
		'keywords' => 'keywords',
	];

	public function getMetaAuthor()
	{
		return $this->author->name;
	}
}
```

## View

In your view:

```php
@extends ('layout')

@section ('metadata')
{!! $post->meta() !!}
@endsection
```

The layout:

```php
<head>
@yield('metadata')
</head>
```

So now the author attribute will be called through this method instead.

## OpenGraph

```php
<?php App\Post;

use Dishark\Metaeloquent\Traits\MetaTrait;

class Post {
	use MetaTrait;

	protected $metaAttributes = [
		'author' => 'author',
		'description' => 'title',
		'keywords' => 'keywords',

		'og:title' => 'name',
		'og:image' => 'image',
		'og:type' => 'article',
		'og:url' => 'url'
	];

	public function getMetaImage()
	{
		return asset('images_path/' . $this->image);
	}

	public function getMetaUrl()
	{
		return route('articles', $this->slug);
	}
}
```

Related Packages

sofa/hookable

Laravel Eloquent hooks system.

2,049,184 65
volosyuk/simple-eloquent

Adaptation of eloquent for retrieving its attributes

117,926 55
gzero/eloquent-tree

Eloquent Tree is a tree model for Laravel Eloquent ORM.

59,480 131
martinbean/laravel-sluggable-trait

A trait you can apply to Eloquent models to have slugs automatically generated o...

49,126 24
isswp101/elasticsearch-eloquent

Elasticsearch functionality like Laravel Eloquent models.

25,356 112

Version History

Version Released License
v1.0 MIT