TypeRocket / laravel by kevindees

Makes form building and model binding a breeze.
3,743
10
3
Package Data
Maintainer Username: kevindees
Package Create Date: 2015-09-22
Package Last Update: 2020-10-06
Home Page: https://packagist.org/packages/typerocket/laravel
Language: PHP
License: GPL-3.0-or-later
Last Refreshed: 2024-12-02 03:03:51
Package Statistics
Total Downloads: 3,743
Monthly Downloads: 6
Daily Downloads: 0
Total Stars: 10
Total Watchers: 3
Total Forks: 2
Total Open Issues: 0

TypeRocket for Laravel 5.3

Originally for WordPress, TypeRocket makes building advanced forms and fields easy for Laravel too.

See http://typerocket.com for documentation (mainly for WordPress).

Installing

composer require typerocket/laravel

Laravel Service Providers make a way for extending Laravel. TypeRocket Laravel 2.0 is a service provider for Laravel. In your config/app.php file add:

'providers' => [
    // Other Service Providers

    TypeRocket\Service::class,
],

Then form the command line:

php artisan vendor:publish --provider="TypeRocket\Service"

You can now access the config/typerocket.php.

Finally, add uploads to public folder. From your site root directory run:

ln -s ../storage/uploads uploads

Note: Routes, views, and controller will be adding for you.

JS and CSS init

In blade templates such master templates.

{!! \TypeRocket\Assets::getHeadString() !!}
{!! \TypeRocket\Assets::getFooterString() !!}

Adding assets

$paths = Config::getPaths();

// type ( js || css), id, path
Assets::addToFooter('js', 'typerocket-core', $paths['urls']['js'] . '/typerocket.js');
Assets::addToHead('js', 'typerocket-global', $paths['urls']['js'] . '/global.js');

Forms

// model, action ( create || update ), id, path
$form = new \TypeRocket\Form('Post', 'update', $id, '/posts/' . $id);
<div class="typerocket-container">
    {!! $form->open() !!}
    {!! $form->text('title')->setLabel('Post Title') !!}
    {!! $form->checkbox('publish')->setText('Published') !!}
    {!! $form->close('Submit') !!}
</div>

Request Old Input

To load old input into the form set the request.

class PostController extends Controller
{
    public function create(Request $request)
    {
        $form = new \TypeRocket\Form('Post', 'create', null, '/posts/');
        $form->setRequest($request); // set request
        return view('posts.create', ['form' => $form]);
    }
}

Validate

class PostController extends Controller
{

    public function store(Request $request)
    {
        $tr = $request->input('tr');

        $validator = \Validator::make($tr, [
            'title' => 'required|max:255'
        ]);

        if ($validator->fails()) {
            return redirect("posts/create")
                ->withErrors($validator)
                ->withInput();
        }

        $post = new Fabric();
        $post->title = $tr['title'];
        $post->save();

        header('Location: /posts/');
    }

}

Matrix route.

Working with matrix fields the service provider will add this for you.

Route::post('matrix_api/{group}/{type}', function($group, $type) {
    (new TypeRocket\Matrix())->route($group, $type);
});

CSFR for matrix

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'matrix_api/*' // added
    ];
}

Matrix Assets

Assets will not be loaded form fields because the view is already loaded. Include the possible assets in the controller.

For example a Matrix field that uses an image field will need to include image.js.

$paths = \TypeRocket\Config::getPaths();
\TypeRocket\Assets::addToFooter('js', 'typerocket-image', $paths['urls']['js'] . '/image.js');

Media

Typerocket Media uses https://github.com/eventviva/php-image-resize to create thumbnails.

Unsplash

To enable, set the typerocket.media.unsplash.enabled to true, and set the the Unsplash client ID in typerocket.media.unsplash.client_id.

To add the Unsplash button and modal anywhere, use the custom Blade directive @tr_unsplash.