• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 4 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A collection of Laravel goodies.

Laravel Mixins

Latest Version on Packagist Build Status Quality Score Total Downloads Buy us a tree

Sponsor this package!

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

Laravel Splade

Did you hear about Laravel Splade? 🤩

It's the magic of Inertia.js with the simplicity of Blade. Splade provides a super easy way to build Single Page Applications using Blade templates. Besides that magic SPA-feeling, it comes with more than ten components to sparkle your app and make it interactive, all without ever leaving Blade.

Requirements

  • PHP 8.0+
  • Laravel 9.0

Installation

You can install the package via composer:

composer require protonemedia/laravel-mixins

There's no Service Provider or automatic discovery/registration of anything. All features are opt-in.

Contents

Blade Directives

Console Commands

Validation Rules

String Macros

PDF

Request

Blade Directives

You can register Blade Directives by calling the directive method on the class. You can change the name of a directive with the optional first argument.

Decimal Money Formatter

Note: This directive requires the moneyphp/money package.

Register the directive, for example by adding it to your AppSerivceProvider:

ProtoneMedia\LaravelMixins\Blade\DecimalMoneyFormatter::directive();

You can customize the name of the directive and the default currency code:

ProtoneMedia\LaravelMixins\Blade\DecimalMoneyFormatter::directive('decimals', 'EUR');

The first argument of the directive is the amount in cents. The second optional parameter is the currency.

// 0.99
@decimals(99)

// 1.00
@decimals(100)

// 100
@decimals(100, 'XTS')

Intl Money Formatter

Note: This directive requires the moneyphp/money package.

Register the directive, for example by adding it to your AppSerivceProvider:

ProtoneMedia\LaravelMixins\Blade\IntlMoneyFormatter::directive();

You can customize the name of the directive, the default currency code and the locale:

ProtoneMedia\LaravelMixins\Blade\IntlMoneyFormatter::directive('money', 'EUR', 'nl_NL');

The first argument of the directive is the amount in cents. The optional second parameter is the currency. The optional third parameter is the locale.

// € 0,99
@money(99)

// € 1,00
@money(100)

// US$ 1,00
@money(100, 'USD')

// 1 000,00 $US
@money(100, 'USD', 'fr')

Commands

Generate Sitemap

Note: This command requires the spatie/laravel-sitemap package.

You can register the command by adding it to your App\Console\Kernel file, or by calling the register method on the class.

ProtoneMedia\LaravelMixins\Commands\GenerateSitemap::register();

You can also set a custom signature:

ProtoneMedia\LaravelMixins\Commands\GenerateSitemap::register('generate-sitemap');

It generates a sitemap of your entire site and stores in in the public folder as sitemap.xml.

php artisan sitemap:generate

Validation Rules

Current password

Passes if the value matches the password of the authenticated user.

$rule = new ProtoneMedia\LaravelMixins\Rules\CurrentPassword;

As of Laravel 9, this validation rule is built-in.

Dimensions With Margin

Extension of the Dimensions rule with a margin option. Handy when you're working with ratios with repeating decimals.

use ProtoneMedia\LaravelMixins\Rules\DimensionsWithMargin;

$rule = DimensionsWithMargin::make()->ratio(20 / 9)->margin(1),

Host

Verifies if the URL matches the given hosts.

use ProtoneMedia\LaravelMixins\Rules\Host;

$rule = Host::make(['facebook.com', 'fb.me']);

In Keys

Verifies if the given key or index exists in the array.

use ProtoneMedia\LaravelMixins\Rules\InKeys;

$rule = new InKeys(['laravel' => 'Laravel Framework', 'tailwindcss' => 'Tailwind CSS framework']);

// same as

use Illuminate\Validation\Rules\In;

$rule = new In(['laravel', 'tailwindcss']);

Max Words

Passes if the values contains no more words than specified.

use ProtoneMedia\LaravelMixins\Rules\MaxWords;

$rule = MaxWords::make(250);

URL Without Scheme

Passes if the URL is valid, even without a scheme.

$rule = new ProtoneMedia\LaravelMixins\Rules\UrlWithoutScheme;

String macros

You can add new method by using the mixins.

Compact

Str::mixin(new ProtoneMedia\LaravelMixins\String\Compact);

$string = "Hoe simpeler hoe beter. Want hoe minder keuze je een speler laat, hoe groter de kans dat hij het juiste doet.";

// Hoe simpeler hoe beter. Want hoe ... de kans dat hij het juiste doet.
echo Str::compact($string);

It has an optional second argument to specify the length on each side. With the optional third argument, you can specify the sepeator.

// Hoe simpeler hoe - het juiste doet.
echo Str::compact($string, 16, ' - ');

Human Filesize

Converts a filesize into a human-readable version of the string.

Str::mixin(new ProtoneMedia\LaravelMixins\String\HumanFilesize);

$size = 3456789;

// '3.3 MB'
Str::humanFilesize($size));

Text

Note: This macro requires the html2text/html2text package.

Converts HTML to plain text.

Str::mixin(new ProtoneMedia\LaravelMixins\String\Text);

$html = "<h1>Protone Media</h1>";

// Protone Media
Str::text($html);

URL

Prepends https:// if the scheme is missing from the given URL.

Str::mixin(new ProtoneMedia\LaravelMixins\String\Url);

$url = "protone.media";

// https://protone.media
Str::url($url);

Seconds to time

Converts seconds to a 'mm:ss' / 'hh:mm:ss' format.

Str::mixin(new ProtoneMedia\LaravelMixins\String\SecondsToTime);

Str::secondsToTime(10); // 00:10
Str::secondsToTime(580); // 09:40
Str::secondsToTime(3610); // 01:00:10

// force 'hh:mm:ss' format, even under an hour:
Str::secondsToTime(580, false); // 00:09:40

PDF Regeneration

Note: Requires the symfony/process package.

Regenerates the PDF content with Ghostscript.

$ghostscript = new ProtoneMedia\LaravelMixins\Pdf\Ghostscript;

$regeneratedPdf = $ghostscript->regeneratePdf(
    file_get_contents('/uploads/invoice.pdf')
);

You can specify the path of the ghostscript binary as well:

$ghostscript = new Ghostscript('gs-binary');

Convert Base64 input data to files

Add the ConvertsBase64ToFiles trait and base64FileKeys method to your form request.

use Illuminate\Foundation\Http\FormRequest;
use ProtoneMedia\LaravelMixins\Request\ConvertsBase64ToFiles;

class ImageRequest extends FormRequest
{
    use ConvertsBase64ToFiles;

    protected function base64FileKeys(): array
    {
        return [
            'jpg_image' => 'Logo.jpg',
        ];
    }

    public function rules()
    {
        return [
            'jpg_image' => ['required', 'file', 'image'],
        ];
    }
}

Now you can get the files like regular uploaded files:

$jpgFile = $request->file('jpg_image');

// Logo.jpg
$jpgFile->getClientOriginalName();

This trait supports nested data as well. You can either reference the keys by a nested array, or with a dotted notation:

class ImageRequest extends FormRequest
{
    use ConvertsBase64ToFiles;

    protected function base64FileKeys(): array
    {
        return [
            'company.logo' => 'Logo.jpg',
            'user' => [
                'avatar' => 'Avatar.jpg',
            ],
        ];
    }
}

Want to know more about this trait? Check out the blog post.

Testing

composer test

Changelog

Please see CHANGELOG for more information 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 Cross Eloquent Search: Laravel package to search through multiple Eloquent models.
  • 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 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 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.
  • Laravel Eloquent Where Not: This Laravel package allows you to flip/invert an Eloquent scope, or really any query constraint.

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.

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.

More Repositories

1

laravel-ffmpeg

This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.
PHP
1,511
star
2

laravel-splade

💫 The magic of Inertia.js with the simplicity of Blade 💫 - Splade provides a super easy way to build Single Page Applications (SPA) using standard Laravel Blade templates, and sparkle it to make it interactive. All without ever leaving Blade.
PHP
1,382
star
3

laravel-cross-eloquent-search

Laravel package to search through multiple Eloquent models. Supports sorting, pagination, scoped queries, eager load relationships and searching through single or multiple columns.
PHP
990
star
4

laravel-form-components

A set of Blade components to rapidly build forms with Tailwind CSS (v1.0 and v2.0) and Bootstrap 4/5. Supports validation, model binding, default values, translations, Laravel Livewire, includes default vendor styling and fully customizable!
PHP
807
star
5

inertiajs-tables-laravel-query-builder

Inertia.js Tables for Laravel Query Builder
PHP
425
star
6

eddy-server-management

Open-Source Solution for Server Provisioning and Zero-Downtime PHP Deployment
PHP
423
star
7

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.
PHP
384
star
8

laravel-analytics-event-tracking

Laravel package to easily send events to Google Analytics
PHP
243
star
9

laravel-paddle

Paddle.com API integration for Laravel with support for webhooks/events
PHP
195
star
10

laravel-task-runner

A package to write Shell scripts like Blade Components and run them locally or on a remote server
PHP
116
star
11

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.
PHP
102
star
12

laravel-single-session

This package prevents a User from being logged in more than once. It destroys the previous session when a User logs in and thereby allowing only one session per user.
PHP
101
star
13

laravel-xss-protection

Laravel XSS Protection Middleware
PHP
99
star
14

laravel-guidelines

Not necessarily coding standards (naming conventions, avoid else, etc.), but more like 'app'-guidelines - things you don't want to forget.
PHP
91
star
15

laravel-api-health

Monitor first and third-party services and get notified when something goes wrong!
PHP
87
star
16

form-components-pro

A set of Vue 3 components to rapidly build forms with Tailwind CSS 3. It supports validation, model binding, integrates with Autosize/Choices.js/Flatpickr, includes default vendor styling and is fully customizable! Even better in conjunction with Laravel Jetstream + Inertia.js.
JavaScript
82
star
17

laravel-webdav

WebDAV Serivce Provider for Laravel
PHP
59
star
18

laravel-blade-on-demand

Compile Blade templates in memory
PHP
50
star
19

inertia-vue-modal-poc

Proof of Concept: Load any route into a modal with Inertia.js
Vue
49
star
20

laravel-splade-core

A package to use Vue 3's Composition API in Laravel Blade components.
PHP
42
star
21

laravel-eloquent-where-not

This Laravel package allows you to flip/invert an Eloquent scope, or really any query constraint.
PHP
27
star
22

laravel-content

You provide the WYSIWYG editor, Media uploader, etc., and the package handles the validation, multi-language, storage, caching, sanitizing, etc.
PHP
23
star
23

inertiajs-events-laravel-dusk

Inertia.js Events for Laravel Dusk
PHP
22
star
24

laravel-dusk-fakes

Persistent Fakes for Laravel Dusk
PHP
17
star
25

laravel-minio-testing-tools

This package provides a trait to run your tests against a MinIO S3 server.
PHP
11
star
26

splade.dev

Source code for https://splade.dev
PHP
8
star
27

laravel-splade-docs

7
star
28

laravel-viewi

[WIP] Viewi for Laravel proof-of-concept: Build full-stack and completely reactive user interfaces with PHP.
PHP
5
star
29

eddy-backup-cli

Backup CLI for Eddy Server Management
PHP
3
star
30

form-components-pro-docs

A set of Vue components to rapidly build forms with Tailwind CSS v2.0. It supports validation, model binding, includes default vendor styling and is fully customizable!
JavaScript
3
star
31

laravel-tracer

[WIP] Trace authenticated users
PHP
2
star
32

eddy-filesystem-cli

PHP
1
star
33

laravel-ffmpeg-demo-app

A demo app to show all the cool things you can do with Laravel FFmpeg
1
star
34

php-apple-mapkit-token

Create a MapKit JS Token with PHP
1
star
35

laravel-browser-kit-macro

A macro to use the Laravel 5.3 testing layer inside your Laravel >5.3 tests
PHP
1
star
36

laravel-splade-plugin-skeleton

PHP
1
star