PHP code example of marshmallow / helpers

1. Go to this page and download the library: Download marshmallow/helpers library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

marshmallow / helpers example snippets


$headers = ['Column 1', 'Column 2', 'Column 3'];
$data = [
	[1, 2, 3],
	[4, 5, 6],
];

return CSV::headers($headers)
	->data($data)
	->delimiter(';')
	->setFilename('generated-csv-1234')
	->storeAndDownload();

use Marshmallow\HelperFunctions\Facades\CSV;

CSV::headers($headers)
        ->data($data, function (array $row) {
            return [
                $row['name'],
                $row['slug'],
                $row['created_at'],
            ];
        })
        ->storeAndDownload();

$csv->download();
$csv->store();
$csv->storeAndDownload();
$csv->stream();

percentage(47, App\Post::get()); // 63.829787234043

Str::join([
  'Marshmallow',
  'Stef van Esch',
  'Mr Mallow'
]);

// Marshmallow, Stef van Esch and Mr Mallow

Str::random($limit = 16, $ignore = [
    /**
     * Custom items
     */
    'A','B', 'C', 'D',

    /**
     * Presets
     */
    'lowercase', 	// Will ignore all lowercase characters.
    'uppercase',	// Will ignore all uppercase characters.
    'letters',		// Will ignore all letters.
    'numbers',		// Will ignore all numbers.
    'similar',		// Will ignore all numbers and letters that have been marked as similar.
]);

Str::cleanPhoneNumber()

Str::phonenumberWithCountryCode('0628998954')
// response: +31628998954

Str::phonenumberWithCountryCode(
    '0031628998954',
    $country_code = '31',
    $use_plus_instead_of_zeros = false
);
// response: 0031628998954

Str::numbersOnly()

Str::numbersAndLettersOnly()

Str::readmore(
    $string,
    $lenght_first_part,
    $return_this_part = null
);

Str::paragraphsAsArray($string);

Str::getFirstParagraph(
    $string,
    $number_of_paragraphs = 1,
    $return_array = false
);

Str::getAllButFirstParagraph(
    $string,
    $number_of_paragraphs_to_skip = 1,
    $return_array = false
);

use Marshmallow\HelperFunctions\Traits\MigrationHelper;

class CreateProductTable extends Migration
{
    use MigrationHelper;

$this->createColumnIfDoesntExist(
    'products', 'deleted_at', function (Blueprint $table) {
        $table->softDeletes();
    }
);

URL::isInternal($url)

URL::isCurrent($url)

URL::buildFromArray($array)

URL::isNova($request)

URL::isNotNova($request)

Arrayable::storeInFile(array $array, string $file_location);

public function scopePublished (Builder $builder)
{
    BuilderHelper::published(
        $builder,
        $valid_from_column,
        $valid_till_column
    );
}

return [
    'max_rating' => 10,
    'full_star' => '+ ',
    'half_star' => '* ',
    'empty_star' => '- ',
];

ReviewHelper::ratingToStars(4.5, [
    'max_rating' => 10,
    'full_star' => '+ ',
    'half_star' => '* ',
    'empty_star' => '- ',
])

use Marshmallow\HelperFunctions\Facades\Collection;

$grouper = Collection::createGrouper(Blog::get(), $structure_array = [
    'first' => 3,
    'second' => 1,
    'third' => 2,
]);

foreach ($grouper as $group) {
    if ($group->is('first')) {
        // Add your template for 3 items
    }

    if ($group->is('second')) {
        // Add your template for 1 item
    }
}

foreach ($grouper as $group) {
    foreach ($group as $blog) {
        //
    }
}