protonemedia/laravel-content

Laravel package to handle content.

dev-main 2021-01-19 23:01 UTC

This package is auto-updated.

Last update: 2022-05-20 01:53:40 UTC


README

https://twitter.com/pascalbaljet/status/1348562877230280709

Don't use in production yet!

This package will be a companion to Form Components Pro.

Latest Version on Packagist run-tests Quality Score Total Downloads Buy us a tree

Requirements

  • PHP 7.4+
  • Laravel 6.0 and higher

Features

Defining pages:

use ProtoneMedia\LaravelContent\Fields\Html;
use ProtoneMedia\LaravelContent\Fields\Image;
use ProtoneMedia\LaravelContent\Fields\Text;
use ProtoneMedia\LaravelContent\Pages\Page;

class ContactPage extends Page
{
    public function fields(): array
    {
        return [
            'title'    => new Text,
            'header'   => new Image,
            'contents' => new Html,
        ];
    }
}

$field = new Html;
$field = Html::make();

$field = Html::make()
    ->addToRules([new NoJavascriptRule, new NoExternalHostsRule])  // optional
    ->beforeSaving(new HtmlPurifier), // optional

Create/update from Request:

$newPageModel = ContactPage::fromRequest()->validate()->saveToModel(new PageModel);

// from request:
$contactPage = ContactPage::fromRequest()
$contactPage = ContactPage::fromRequest($request);

// validation:
$contactPage->validate();
$contactPage->getRules();
$contactPage->getValidator();

// save to database:
$contactPage->saveToModel($yourModel);
$contactPage->saveToModel($yourModel, 'field');

$contactPage->toJson();

Fields as Eloquent Casts:

use ProtoneMedia\LaravelContent\Fields\Image;
use ProtoneMedia\LaravelContent\Fields\Markdown;

class BlogPost extends Model
{
    protected $casts = [
        'top_image' => Image::class,
        'contents' => Markdown::class,
    ];
}

Standalone fields:

$field = Markdown::fromInput(request('contents'))
    ->withMiddleware(ReplaceOldHostnames::class);

BlogPostModel::first()->update([
    'contents' => $field->getValue()
]);

Media fields can have a custom backend:

Image::setDefaultRepositoryResolver(function() {
    return new MediaLibraryRepository;
});

Fields can be used in Blade views:

{{ $page->image }}

Which is equal to:

$page->image->toHtml();

Blogpost

...

Support

We proudly support the community by developing Laravel packages and giving them away for free. Keeping track of issues and pull requests takes time, but we're happy to help! If this package saves you time or if you're relying on it professionally, please consider supporting the maintenance and development.

Installation

You can install the package via composer:

composer require protonemedia/laravel-content

Usage

...

Testing

composer test

Changelog

Please see CHANGELOG for more information about what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Other Laravel packages

  • Laravel Analytics Event Tracking: Laravel package to easily send events to Google Analytics.
  • Laravel Blade On Demand: Laravel package to compile Blade templates in memory.
  • Laravel Eloquent Scope as Select: Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.
  • Laravel Cross Eloquent Search: Laravel package to search through multiple Eloquent models.
  • Laravel Eloquent Where Not: This Laravel package allows you to flip/invert an Eloquent scope, or really any query constraint.
  • Laravel FFMpeg: This package provides an integration with FFmpeg for Laravel. The storage of the files is handled by Laravel's Filesystem.
  • Laravel Form Components: Blade components to rapidly build forms with Tailwind CSS Custom Forms and Bootstrap 4. Supports validation, model binding, default values, translations, includes default vendor styling and fully customizable!
  • Laravel Mixins: A collection of Laravel goodies.
  • Laravel Paddle: Paddle.com API integration for Laravel with support for webhooks/events.
  • Laravel Verify New Email: This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.
  • Laravel WebDAV: WebDAV driver for Laravel's Filesystem.

Security

If you discover any security related issues, please email pascal@protone.media instead of using the issue tracker.

Credits

License

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

Treeware

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.