Download the PHP package onpage-dev/laravel-plugin without Composer
On this page you can find all versions of the php package onpage-dev/laravel-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-plugin
On Page ® Laravel plugin
This package implements all the OnPage data and data structure in any Laravel application. All the CLI command have to be execute at your Laravel project main directory.
Installation
Add the repository to your composer file and install the package:
Publish the configuration file
Run plugin migrations (we use the op_*
prefix for our tables)
Upgrade
Run plugin migrations (we use the op_*
prefix for our tables)
Configuration
- Go to your On Page and generate a new snapshot from the "Snapshot Generator" section
- Copy the Snapshot Generator API token
- Add the following to your
.env
file:
By default, the plugin will create a onpage-models
directory in your base directory.
The folder will be filled with On Page generated models, which you should not modify, as they are generated automatically.
By default, the models will live in the Data namespace, so you can access them using \Data\ModelName::...
.
To make this work, you need to instruct composer to preload this folder.
Finally make sure to update composer.
Import data
To import your data execute this command:
Error prevention
If some resources or fields have been removed or changed, the import will prompt you whether you want to continue or not. You can use the --force
flag to ignore this warning.
Useless import prevention
If you try to import same data you already have, the import is stopped. You can use the --anyway
flag to ignore this warning.
Restore a previous snapshot
Each time you import data, the snapshot is saved locally in your Laravel project. If you want to restore a previous snapshot execute the rollback command and digit the number associated at the snapshot choosen.
Querying data
Because the plugin does not actually generate tables and columns corresponding for your data, you will have to use the whereField
function instead of the where
clause, which works in the same manner.
If you have trouble doing some operations, please open an issue explaining your use case.
Advanced whereField clauses:
If you need to query data with advanced where*
clauses, you have to use the advanced whereField*
functions.
You can also combine them to obtain more advanced clauses, which work in the same manner.
Getting values
Once you get your records, you need to display the related data.
To access field data for a record, you need to use the ->val($field_name, $lang)
function.
The $lang
is set to use the current default language.
Examples:
Multivalue fields
For fields which contain multiple values, the val
function will always return a collection of the values:
File and image fields
For these files, the returned value will be an instance of \OnPage\File::class
.
To get a file or image url use the ->link()
function. The link will point to the original file.
To turn images into a thumbnail add an array of options as shown below:
Getting Resources and Fields
`
Using Fields Folders
`