Laravel Blade directive for conditional HTML classes

Sometimes you need to add classes to HTML elements conditionally, and when you try to do that you almost always end up with messy syntax. Here’s the example in Blade:

<article class="post post-{{ $post->slug }} @if ($post->featured) post-featured @endif @if ($post->sticky) post-sticky @endif">
    ...
</article>

Or with pure PHP:

<article class="post post-<?php echo $post->slug ?> <?php if ($post->featured): ?>post-featured<?php endif ?> <?php if ($post->sticky): ?>post-sticky<?php endif ?>">
    ...
</article>

And if you split it into multi-line you get even worse, and when you add even more conditional classes you get if mess.

Continue reading

Share this ...Tweet about this on TwitterShare on FacebookEmail this to someoneShare on RedditShare on Google+Share on LinkedInPin on Pinterest

Laravel Excel Package

Laravel Excel brings the power of PHPOffice’s PHPExcel to Laravel 5 with a touch of the Laravel Magic. It includes features like: importing Excel and CSV to collections, exporting models, array’s and views to Excel, importing batches of files and importing a file by a config file.

Sample:

Excel::create('Laravel Excel', function($excel) {

    $excel->sheet('Excel sheet', function($sheet) {

        $sheet->setOrientation('landscape');

    });

})->export('xls');

 

See more at:

https://github.com/Maatwebsite/Laravel-Excel

Documentation:

http://www.maatwebsite.nl/laravel-excel/docs

To install with Composer:

composer require maatwebsite/excel

 

Share this ...Tweet about this on TwitterShare on FacebookEmail this to someoneShare on RedditShare on Google+Share on LinkedInPin on Pinterest

How to pass data to JavaScript with Basset?

This article explains how to pass data from server PHP to JavaScript with Basset – better asset management for Laravel.

Sometimes you will want to pass data from server PHP to JavaScript but without API. It can be to preload data, or to pass some server specific data which shouldn’t be in API’s.

You can use Basset\Javascript class for that. Whatever you set on this class will be available from the browser JavaScript runtime.

Continue reading

Share this ...Tweet about this on TwitterShare on FacebookEmail this to someoneShare on RedditShare on Google+Share on LinkedInPin on Pinterest

Basset – auto .min swapping

Normally, for production build, Basset runs UglifyJS to minify JavaScript, and you get pretty good results from minifying with UglifyJS.

Sometimes third party code (like in bower_components) comes with .min files, already minified files. They are most often minified with UglifyJS.

But sometimes libraries, like AngularJS, come with files minified with Google’s Closure Compiler, which can sometimes have even smaller files then UglifyJS (if you specifically optimize your code for Closure Compiler).

And if you use many of those libraries, you can cut down on your build sizes a lot.

Basset can use that. Basset has feature “auto .min swapping” which will try to discover those .min files and use their content instead of normal raw source files. Those .min files will still go through UglifyJS, but the benefits of Closure Compiler, or any other different minifier, will remain there.

So you can just use gulp production build with Bower components and never think about it. Basset will do the rest for you.

Share this ...Tweet about this on TwitterShare on FacebookEmail this to someoneShare on RedditShare on Google+Share on LinkedInPin on Pinterest