Download the PHP package okipa/laravel-brickables without Composer

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

Package abandoned

This package has been abandoned, use with caution if you still need it.
Please fork this package and give it new life if you're interested!


Latest Stable Version Total Downloads Build Status Coverage Status License: MIT

This package allows you to associate content bricks to Eloquent models and provides a fully customizable admin panel to manage them.

This package is shipped with few pre-built brickables. You can use them as is but you definitely should consider them as examples: customizing them or create new ones has been designed to be simple as hell! :fire:

Found this package helpful? Please consider supporting my work!

Donate Donate

Compatibility

Laravel version PHP version Package version
^9.0 | ^10.0 8.1. | 8.2. ^3.2
^8.0 | ^9.0 ^8.1 | ^8.2 ^3.1
^8.0 | ^9.0 ^8.0 | ^8.1 ^3.0
^7.0 | ^8.0 ^7.4 | ^8.0 ^2.0
^5.8 | ^6.0 | ^7.0 ^7.1 | ^7.2 | ^7.3 | ^7.4 ^1.0

Upgrade guide

Usage

Associate content bricks to Eloquent models:

Display bricks in your views:

Display the model-related bricks admin panel in your views:

Table of contents

Installation

Install the package via composer:

Then, publish and run the database migrations:

Finally, to benefit from smart loading of brickables css and js resources, add these directives to your blade layout as shown in the example bellow:

Configuration

Publish the package configuration:

:warning: You may have to run a composer dump-autoload after changing a path in your configuration file.

Views

Publish the package views:

Translations

All words and sentences used in this package are translatable.

See how to translate them on the Laravel official documentation : https://laravel.com/docs/localization#using-translation-strings-as-keys.

Here is the list of the words and sentences available for translation by default:

You will also have to define the validation.attributes.brickable_types translation.

Finally, you will have to translate each registered brickable label translation.

Implementation

Models

Implement the HasBrickables interface and use the HasBrickablesTrait trait to any Eloquent model that you want to be able to be associated to content bricks to.

Routes

Add the web routes that will be required by the content bricks admin panel:

These routes are consuming the Okipa\LaravelBrickables\Controllers\BricksController controller by default.

To customize the admin panel actions, you can add routes inside or outside of the brickables route group.

Check the Empower bricks with extra abilities part to get more information about the customization possibilities.

How to

Define brick constraints for model

In your Eloquent model, you optionally can define constraints:

In this example:

Important note: you can disable a brickable management for a model by setting its max number to 0.

Add content bricks

Associate a single content brick to an Eloquent model:

You also can associate several content bricks at once:

Update a content brick

Just update your content brick as you would fo for any other Eloquent model instance:

Remove content bricks

Just delete your content brick as you would fo for any other Eloquent model instance:

Clear all the content bricks associated to an Eloquent model, or only those with specific brickable types:

Clear all the content bricks except specific ones:

Note

Set content bricks order

By default, all bricks are ordered by their creation order (last created at the end).

The Brick model uses the spatie/eloquent-sortable package to handle the content bricks positioning.

To see how to use this third party package, check its documentation here: https://github.com/spatie/eloquent-sortable.

You may note that the bricks order management is already handled in the provided admin panel and that you can use it as is.

Retrieve content bricks

Retrieve all the content bricks associated to an Eloquent model, or only those with a specific brickable type:

Get the first content brick associated to an Eloquent model, or the one with a specific brickable type:

Query content bricks

As each brickable can specify its own brick model, you should query content bricks and then cast them ito the model defined in their related brickable:

Display content bricks

Display a single content brick in your view:

Or display all the content bricks associated to an Eloquent model:

Or only display content bricks from given brickable types:

Retrieve brickables

Get all the registered brickables:

Get all the brickables that are allowed to be added to an Eloquent model:

Retrieve a brickable from a brick instance:

Manage model content bricks

Use the ready-to-use admin panel to manage related-model content bricks:

Customize the admin panel views by publishing them.

:bulb: Tips

Create your own brickable

Create a new brickable class that extends class in your app/vendor/Brickables directory.

In your brickable class, you can override any method from the extended abstract Brickable to customize the brickable behaviour.

Then, register it in your config('brickables.registered') array:

Finally, create the brickable views in the resources/views/vendor/laravel-brickables/my-new-brickable directory (you can customize the view paths in your MyNewBrickable class):

You should see the existing brickables implementation to get familiar with their management.

Your brickable is now ready to be associated to Eloquent models.

Define brickable css and js resources

You have the possibility to define a css and js resource to customize each brickable rendering.

In addition, this package embeds a smart resource management system : it determines which brickables are actually displayed on the page and only loads the resources once, even if a brickable is used more than once on the page.

To benefit from this feature, make sure you have implemented the @brickablesCss and the @brickablesJs directives as precised in the installation part.

Then, define which resources your brickables are using:

Finally, use the @brickableResourcesCompute directive under the last displayed brick in the page:

:warning: Important: Please note that you will always have to declare the @brickableResourcesCompute directive from a child view from the one which is declaring the brickablesCss and @brickablesJs directives. As you can see in our example, the @brickableResourcesCompute blade directive is called on the page.blade.php view, which is a child of layout.blade.php (where the brickablesCss and @brickablesJs are declared). This is the only way for this package to know which brickables are actually displayed on the page, in order to intelligently load the resources.

Empower brickables with extra abilities

To add abilities to your brickables, you will have to implement the additional treatments in the brickable-related brick model and brick controller.

Let's add the ability to manage images in our MyNewBrickable from the previous example.

First create a MyNewBrickableBrick model that will extend the Okipa\LaravelBrickables\Models\Brick one in order to give the image management ability to this brick.

Then, create a MyNewBrickableBricksController model which will extend the Okipa\LaravelBrickables\Controllers\BricksController one where you will add the image management treatments.

Do not forget to validate your form inputs:

Finally, tell you brickable to use your MyNewBrickableBrick model and your MyNewBrickableBricksController controller:

That's it, your custom model and controller will now be used by the MyNewBrickable brickable.

Get Eloquent model from request

It can be useful to retrieve the Eloquent model from the request, for navigation concerns, for example.

This helper will be able to return the related model when navigating on the brickables form views (bricks creation and edition requests).

Testing

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-brickables with dependencies

PHP Build Version
Package Version
Requires php Version 8.1.*|8.2.*
illuminate/contracts Version ^9.0|^10.0
spatie/eloquent-sortable Version 4.0.2
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 okipa/laravel-brickables contains the following files

Loading the files please wait ....