An open API service indexing awesome lists of open source software.

https://github.com/kfoobar/laravel-meta

Meta and title tag management package for Laravel 5 and Laravel 6
https://github.com/kfoobar/laravel-meta

blade-directives facade laravel meta-tags title-tag

Last synced: 2 months ago
JSON representation

Meta and title tag management package for Laravel 5 and Laravel 6

Awesome Lists containing this project

README

        

# Laravel package to manage meta and title tags

This package makes it easier to work with HTML meta and title tags in Laravel 5 and Laravel 6.

The package can be used in any controller with the facade or in any blade file with the facade or the blade directives.

The package supports most meta tags. It also supports the `` tag and the `` tag for canonical since they are commonly used.

## Installation

Begin by installing the package with Composer from your command line:

```
$ composer require kfoobar/laravel-meta
```

### Laravel 5.5 or later

If you use auto-discovery, you don't need to do anything more to enable the package.

### Laravel 5.4 or earlier

You need to register the service provider with your Laravel application in `config/app.php`:

```php
'providers' => [
'...',
KFoobar\LaravelMeta\MetaServiceProvider::class,
];
```

Also add the facade to the same config file:

```php
'aliases' => [
'...',
'Meta' => KFoobar\LaravelMeta\Facades\Meta::class,
];
```

## How to use

### How to use the facade

If you want to set your tags in a controller, you'll need to add the namespace for the `Meta` facade.

```php

    @getMeta('title', 'Default title if none is set')

```

#### Get the full html tag

You can use the `@getTag` directive when you want to print the full html tag.

```php
@getTag('title')
@getTag('title', 'Default title if none is set')

@getTag('description')
@getTag('description', 'Default description if none is set')
```

#### Check if value is set

When you need the check if any value is set, use the `@hasMeta` directive.

```php
@hasMeta('author')

@endhasMeta
```

You can also use `@endif` instead of `@endhasMeta` if you prefer.

## Example

This is our blade file:

```php
@getTag('description')
@getTag('keywords')
@getTag('robots', 'index, follow')
@getTag('csrf-token')

@getTag('title', 'Default title if none is set')

@hasMeta('canonical')
    @getTag('canonical')
@endhasMeta
```

This will be the output:

```php

Default title if none is set

```

## Contributing

Contributions are welcome!

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.