Seo Manager Package for Laravel ( with Localization )
lionix/seo-manager package will provide
you an interface from where you can manage all your pages
metadata separately and get dynamically changing content.
Let's see how.
Update:
After updating to version > v1.2.* you have to run:
to publish latest configs and new migration files.
Localization
In version v1.2.* you will have availability
to localize your metadata and set translates
to your data.
For that, you just should
add your available locales
with top right button "Add Locales" and
chose locale for which you want to add translations.
That's it,
Package will automatically detect your locale
from website and will set needed translations,
you don't need to do any other configs.
Easy, isn't it?
This command will create config/seo-manager.php
file and will copy package assets directory to public/vendor/lionix.
Configurations
In config/seo-manager.php file you can do the following configurations:
return [
/** * Database table name where your manager data will be stored */'database' => [
'table' => 'seo_manager',
'locales_table' => 'seo_manager_locales',
'translates_table' => 'seo_manager_translates'
],
/** * Set default locale, * It will be added as default locale * when locales table migrated */'locale' => 'en',
/** * Path where your eloquent models are */'models_path' => '',
/** * Route from which your Dashboard will be available */'route' => 'seo-manager',
/** * Middleware array for dashboard * to prevent unauthorized users visit the manager */'middleware' => [
// 'auth',
],
/** * Routes which shouldn't be imported to seo manager */'except_routes' => [
'seo-manager',
'admin'//
],
/** * Columns which shouldn't be used ( in mapping ) */'except_columns' => [
// "created_at",// "updated_at",
],
/** * Set this parameter to true * if you want to have "$metaData" variable * shared between all views in "web" middleware group */'shared_meta_data' => false
];
After finishing with all configurations run php artisan migrate to create SEO manager table.
That's it, now your SEO manager will be available
from /seo-manager URL (or, if you changed route config,
by that config URL)
Usage
After visiting your dashboard URL you have to import your routes to start to manage them.
Route importing will store all your GET routes into the database ( except the ones which specified in "except_routes" configs).
Let the fun begin!
Mapping
To get dynamically changing metadata you should map your route params to the correct Models.
Param: Route param
Model: Eloquent Model which you are using to get the record by route param
Find By: Database table column name which you are using to get the record by route param
Use Columns: Database table columns which we should use for further mapping
Note: If you have appended attributes inside your model via protected $appends and you want to use them in mapping
you have to use Lionix\SeoManager\Traits\Appends; trait inside your model.
Mapping available only if your route has params
Next steps you can do, is to set Keywords, Description, Title, URL, Author, Title Dynamic, OpenGraph Data.
About "Title Dynamic":
Here you can drag & drop your mapped params, your title and write custom text to generate the dynamic title for your page.
Every time your "title" will be changed or your mapped params value changed, the dynamic title will be changed automatically.
About "Open Graph":
Here you can write your open graph data or map your fields to mapping based on params.
Example Usage
Via SeoManager Facade
useLionix\SeoManager\Facades\SeoManager;
This will return an array with all your SEO Manager data
Note:
You can't add open graph properties to @meta() like @meta('og:url')
But you can get only OpenGraph meta data by @meta('og_data').
If you want to get concrete OG param meta tag you can use @openGraph (similar to @meta('og_data'))
and pass param there like @openGraph('og:url)
Note #2: If you want to do modifications in your og data and display it manually, you should do that before @meta
请发表评论