1. Go to this page and download the library: Download onpage-dev/laravel-plugin library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
onpage-dev / laravel-plugin example snippets
// Search by native fields (id, created_at, updated_at, order)
\Data\Products::where('id', 123123)->first();
// For other fields, use the `whereField` function
\Data\Products::whereField('code', 'AT-1273')->first();
// By default, the filter will be applied on the current locale language
\Data\Products::whereField('description', 'like', '%icecream%')->get();
// You force the filter to search for values in a specific language
\Data\Products::whereField('description.it', 'like', '%gelato%')->paginate();
// To query relations, you can use the standard whereHas laravel function
\Data\Products::whereHas('categories', function($q) {
$q->whereField('is_visible', true);
})->get();
// If you have a file field, you can query by token and by name
\Data\Products::whereField('image:name', 'gelato.jpg')->get();
\Data\Products::whereField('image:token', '79YT34R8798FG7394N')->get();
// For dimension fields (dim2 and dim3) you can use both the x,y,z selectors, or the 0,1,2 selectors
\Data\Products::whereField('dimension:x', '>', 100)->get();
// ... is the same as
\Data\Products::whereField('dimension:0', '>', 100)->get();
// Prefix 'or' for expand the results to another condition
\Data\Products::whereField('name','icecream')->orWhereField('kcal','>',200)->get()
// Suffix 'Not' for negative query
\Data\Products::whereFieldNot('calories','like','low calorie')->get()
// Suffix 'In' for search in an array of values
\Data\Products::whereFieldIn('code',['4','8','15','16','23','42'])->get();
// Maintain proportions width 200px
$product->val('cover_image')->link(['x' => 200])
// Maintain proportions height 100px
$product->val('cover_image')->link(['y' => 100])
// Crop image to width 200px and height 100px
$product->val('cover_image')->link(['x' => 200, 'y' => 100])
// Maintain proportions and contain in a rectangle of width 200px and height 100px
$product->val('cover_image')->link(['x' => 200, 'y' => 100, 'contain' => true])
// Convert the image to png (default is jpg)
$product->val('cover_image')->link(['x' => 200, 'ext' => 'png'])
// Get a resource definition by name:
$prod_res = \Onpage\resource('prodotti') // Returns \OnPage\Resource::class
$prod_res->label; // "Prodotti"
$prod_res->name; // "products"
$prod_res->labels; // [ 'it' => 'Prodotti', 'en' => 'Products' ]
// Get all fields available for this resource:
$weight_field = $prod_res->field('weight'); // Returns \OnPage\Field::class or null
$weight_field->label; // "Peso"
$weight_field->name; // "weight"
$weight_field->type; // "real"
$weight_field->getUnit(); // "kg"
$weight_field->labels; // [ 'it' => 'Peso', 'en' => 'Weight' ]
$weight_field->descriptions; // 'Rappresenta il peso espresso in kg'
$weight_field->description; // [ 'it' => 'Rappresenta il peso espresso in kg', 'en' => 'Represents the weight expressed in kg' ]
// Get all resource fields:
$prod_res->fields // Collection of \OnPage\Field::class
// Print all fields of the products resource
foreach($products->fields as $field) {
echo "- $field->label (type: $field->type)\n"
}
$prod_res = \Onpage\resource('prodotti') // Returns \OnPage\Resource::class
$prod_res->field_folders; // Collection of \OnPage\FieldFolders::class
$field_folder = $prod_res->field_folders->first() // get the first field folder
$field_folder->label; // "Folder1"
$field_folder->fields; // Collection of \OnPage\Field::class
$prod_res->things->first()->default_folder; // Get the default folder for the thing or null