Download the PHP package aruszala/laraberg without Composer

On this page you can find all versions of the php package aruszala/laraberg. 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 laraberg

Latest Version License Gitter

Laraberg aims to provide an easy way to integrate the Gutenberg editor with your Laravel projects. It takes the Gutenberg editor and adds all the communication and data it needs function in a Laravel environment. A demo can be found at demo.laraberg.io. If you would like to see an example of how to implement Laraberg you can take a look at the code from the demo over here.

Table of Contents

Installation

Install package using composer:

Add vendor files to your project (CSS, JS & Config):

In order to store the data for the Gutenberg editor, Laraberg needs to run a database migration:

This will create the 'lb_contents' and 'lb_blocks' tables.

JavaScript and CSS files

The package provides a JS and CSS file that should be present on the page you want to use the editor on:

Dependencies

The Gutenberg editor expects React, ReactDOM, Moment and JQuery to be in the environment it runs in. An easy way to do this would be to add the following lines to your page:

Updating

When updating Laraberg you have to publish the vendor files again by running this command:

Usage

Initializing the Editor

The Gutenberg editor should replace an existing textarea in a form. On submit the raw content from the editor will be put in the 'value' attribute of this textarea.

In order to edit content on an already existing model we have to set the value of the textarea to the raw content that the Gutenberg editor provided.

To initialize the editor all we have to do is call the initialize function with the id of the textarea. You probably want to do this insde a DOMContentLoaded event.

And that's it! The editor will replace the textarea in the DOM and on a form submit the editor content will be available in the textarea's value attribute.

Using the Editor Wihout a Form

If you want to use the editor, but for some reason do not want to deal with submitting forms there is a way to get the content from the editor through JavaScript:

Setting the editor content

It's possible to set the the editor's content using JavaScript:

Configuration options

The init() function takes an optional configuration object which can be used to change Laraberg's behaviour in some ways.

The options object can contain the following optional keys:

Key Type Description
sidebar Boolean Enables the Laraberg sidebar if true
prefix String The API prefix to use for requests (only use this if you changed the API location manually)
laravelFilemanager Bool/Object Enables Laravel Filemanager for fileuploads if value is truth. Can be an object that contains configuration options. See Laravel File Manager.
sidebar Boolean Enables the Laraberg sidebar if true
searchCb Function Will be called when using certain search fields within Gutenberg. See Search Callback.
height String Sets the height of the editor. Value must be a valid css height value (e.g. '10px', '50%', '100vh').
minHeight String Sets the minHeight of the editor. Value must be a valid css min-height value (e.g. '10px', '50%', '100vh').
maxHeight String Sets the maxHeight of the editor. Value must be a valid css max-height value (e.g. '10px', '50%', '100vh').

Models

In order to add the editor content to a model Laraberg provides the 'Gutenbergable' trait.

This adds multiple attributes to your model that will help you with creating/updating/rendering the Gutenberg content.

Note: The old renderContent, getRawContent, getRenderedContent and setContent methods from v0.0.4-beta and lower are deprecated and will be removed in a future release.

Renaming Gutenbergable method names

There is always the possibility that your model already implements a method with the same name as one of the Gutenbergable methods. Luckily PHP Traits provide an easy way to rename the methods from a trait:

In this example you can just call the 'renderLBContent' method to render the content.

Rendering Gutenberg Content

Rendering the Gutenberg content is very simple and happens like this:

Keep in mind that in order to correctly display some of the Wordpress styling the Laraberg CSS has to be present on the page:

Custom Blocks

Gutenberg allows developers to create custom blocks. For information on how to create a custom block you should read the Gutenberg documentation.

Registering Blocks

Registering custom blocks is fairly easy. A Gutenberg block requires the properties title, icon, and categories. It also needs to implement the functions edit() and save().

Registering Categories

If you want to add your custom block to a new category you need to add that category first:

Events

Laraberg implements Laravel events that you can use to implement your own listeners. The events contain a 'content' attribute that contains the relevant Content object. For information on how Laravel events work you can read the Laravel documentation.

Sidebar

Laraberg provides a way to put your form fields in a seperate sidebar in the Gutenberg editor. This way you can let the editor take the entire screen while still having a place for your form fields. This is done by putting the input element in a parent element with the .laraberg-sidebar class. This is currently supported for the following input types:

For the labels Laraberg first checks if there is a label assigned to the element and will try to use that. If there is no label assigned it will check if there is a placeholder and use that as the label.

To enable the sidebar set the sidebar option to true when initializing Laraberg:

Checkbox

Radio

Select

Text

Textarea

Configuration

When initializing the editor there are a number of configuration options you can provide. This is still a work in progress!

Styling

It is possible to set the height, maxHeight, and minHeight of the editor by providing the desired values in the options object:

API Routes

After publishing the vendor files you can find the 'laraberg.php' file in your config folder. This file allows you to configure the API Routes. Here you can change the URL prefix and the middleware for the routes.

When you change the route prefix you also have to provide the prefix when you initialize the editor like this:

If you wish to define the routes yourself you can do that by setting 'use_package_routes' to 'false' in the config. Then you can take the following routes and make changes as you see fit:

Laravel File Manager

Laraberg supports Laravel File Manager for uploading files. To enable uploading media through Laravel File Manager the laravelFilemanager field should be set to true. This will add a 'File Manager' button to the Gutenberg media blocks that will open Laravel File Manager for uploading and selecting media files.

If you are not using the default routes for Laravel File Manager you can provide the location of your Laravel File Manager endpoints in the options object like this:

Note: Laraberg does not do any configuration on your Laravel File Manager setup. By default a lot of media filetypes can not be uploaded unless they are whitelisted in the Laravel File Manager configuration file. For more information on this you can check the Laravel File Manager documentation.

Search Callback

The button block has a field that searches for pages or aritcles. In order to use this functionality you can pass a callback function when initializing Laraberg. This callback functions will receive a search, perPage and type parameter. The callback should return an array of objects that contain a title and an URL or a promise that resolves to such an array.

Missing Blocks

Since we have disabled direct file uploading, some of the media blocks require a media library to operate. This means that the following blocks will only be enabled when you're using Laravel Filemanager for now:

Contributing

If you want to contribute to Laraberg checkout the CONTRIBUTING.md






All versions of laraberg with dependencies

PHP Build Version
Package Version
Requires embed/embed Version ^3.3
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 aruszala/laraberg contains the following files

Loading the files please wait ....