Download the PHP package fsmdev/laravel-page-attributes without Composer

On this page you can find all versions of the php package fsmdev/laravel-page-attributes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-page-attributes

Laravel 5 Page Attributes: meta and other SEO-important attributes

English | Русский

Package for Laravel 5, that helps manage metadata and other page attributes, generate html tags, get page attributes from data base and make own page attributes and html templates for they.

Installation

composer require fsmdev/laravel-page-attributes
For Laravel 5.4 and earlier versions

If you use Laravel 5.5 or higher package discover automatically. For earlier versions add provider and alias in config/app.php file.

Configuration

If you want to change multilanguage mode this can be done by setting the value of the FSMDEV_MULTI_LANGUAGE property in the .env file. By default multi language mode is disabled (false).

For changin

To change other settings, use the file config/page_attributes.php. The file can be created manually or using the command:

php artisan vendor:publish --provider="Fsmdev\LaravelPageAttributes\PageAttributesServiceProvider" --tag=config

Basic usage

Most of the operations described below are performed using the facade PageAttributes.

Setting page attributes

To set the attributes of the page (for example, metadata), the set method of the PageAttributes facade is used.

set ( string|array $name, string $value ) : void

Default values

You can set default values for page attributes. Initially, charset andviewport attributes have default values.

Getting page attributes

To get the page attribute values, use the get method of the PageAttributes facade.

get ( string $name) : string

Getting html

To get html attributes of the page, the method html of the PageAttributes facade is used.

html ( string $name) : string

You can also use Blade directives: @charset, @viewport, @title, @description, @keywords, @canonical.

or

Creating your own templates

The html method uses the predefined html code templates to generate the result. These templates can override or add new templates for your own attributes.

The configuration specified above can be used as follows.

Controller:

View:

Page output:

Default view usage

The package includes a view that displays the following tags: charset, viewport, title, description, keywords, canonical. To use it, add it to the <head> block of the page.

To change the view you need to create a file resouces/views/vendor/page_attributes/meta.blade.php. You can do this automatically with the command:

php artisan vendor:publish --provider="Fsmdev\LaravelPageAttributes\PageAttributesServiceProvider" --tag=view

Overriding the model used in the facade

Change configuration parameter class for change model that uses in PageAttributes facade.

Page Context usage

For separation data and view, it is better to store metadata in a database. When a page is associated with an object of some kind of model, it is easily solved by adding metadata fields to the model. But what to do for pages like main or categories? The page context mechanism offers a solution.

Installation

php artisan vendor:publish --provider="Fsmdev\LaravelPageAttributes\PageAttributesServiceProvider" --tag=context

php artisan migrate

After installation, a file will appear in the app/ConstantsCollections folder with the PageAttributesContext class inherited from ConstantCollection, the table_attributes table will also appear in the database.

Conllection: PageAttributesContext

In this class, you must specify a set of constants corresponding to the pages for which the mechanism for obtaining attributes by context will be used. Constant values must be of type TYNIINT UNSIGNED. It is also recommended to set the names of the constants in the propertiesName method. These names can be further used to create a CRUD of the PageAttribute class.

You can read more about working with the ConstantsCollection class here.

Model: PageAttribute

The package includes a model Fsmdev\LaravelPageAttributes\Models\PageAttribute with table page_attributes. The table (model) contains the following fields:

context (UNSIGNED TINYINT) - contains the value of the constant corresponding to the context for which the attribute is being set.

language (CHAR(2) NULLABLE) - language / locale for which the attribute value is specified. If the use of multi_language is set to false, this attribute is not taken into account when retrieving data.

name (char(30)) - attribute name.

value (text) - attribute value.

Fields context, language and name form a unique index and are key to defining an attribute value.

An example of filling data:

context language name value
5 NULL h1 Awesome Site
5 NULL title Welcome to Awesome Site
5 NULL my_attribute My Value
15 NULL h1 My Blog
Context usage

To set the page attribute context, use the context method of the PageAttributes facade.

context ( integer $context) : void

When the context is set, the get, html methods and blade directives will use the PageAttribute model to find the values of the required attribute:

Returns (for the case when the data is filled as in the table above):

Variables

In page attributes you can use variables. Default syntax:

{--variable_name--}

Opening and closing symbols of variable you can change in configuration parameters variable_open and variable_close.

Variable value set

For variable value set this methods of PageAttributes facade is used:

context ( integer $context, array|null $variables = []) : void

variables ( array $variables) : void

variable ( string $name, string $value) : void

First 2 can get array as parameter. Keys of array are variables names.

Default values

Default values of variables can be set in configuration parameter default_variables.

Example

For page context POST_SHOW set title attribute:

{--post_name--} | Blog | {--site_name--}

Code:

Result in title:

About Me | Blog | Awesome Site

The priority of attribute value selection

When determining the attribute value, the source priority is as follows:

  1. Attributes set directly by the method set;
  2. Attributes received by context (if set);
  3. Attribute default values.

All versions of laravel-page-attributes with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
fsmdev/constants-collection Version ^1.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package fsmdev/laravel-page-attributes contains the following files

Loading the files please wait ....