laravel

All my posts about laravel.

Some Laravel 5 compatible packages

Recently some of the Laravel-packages I built at Spatie were updated for Laravel 5.

spatie/laravel-glide This package enables you to generate image manipulations on the fly and generate URL's to those images. These URL's will be signed so only you will be able to specify which manipulations should be generated. Every manipulation will be cached. Under the hood, Glide is being used.

spatie/searchindex This is an opinionated package to store and retrieve objects from Elasticsearch. It was tailormade for a project I was working on and only provides the functionality that I needed. If you need full control over elasticsearch via PHP, take a look at the official low-level client.

spatie/googlesearch This package can fetch results from a Google Custom Search Engine. It returns an array with searchresults.

eloquent-sortable This package provides a trait that adds sortable behaviour to an Eloquent model. The value of the ordercolumn of a new record of a model is determined by the maximum value of the ordercolumn of all records of that model + 1.

 

A big thank you goes out to Matthias De Winter, who is helping me update these packages.

Read more

The missing tail command for Laravel 5 original

by Freek Van der Herten – 1 minute read

Last week Laravel 5 was released. Unfortunately that handy command for tailing the logs that you know and love from Laravel 4 was not included. The laravel-tail package brings it back. You can install it via composer: composer require spatie/laravel-tail After that you'll have to register the…

Read more

Join 9,500+ smart developers

Get my monthly newsletter with what I learn from running Spatie, building Oh Dear, and maintaining 300+ open source packages. Practical takes on Laravel, PHP, and AI that you can actually use.

No spam. Unsubscribe anytime. You can also follow me on X.

An activity logger for Laravel 5 original

by Freek Van der Herten – 1 minute read

The activitylog-package provides a very easy way to log activities of the users of your app. Today I took the time to make it compatible with Laravel 5. Logging some activity couldn't be easier: [code] /* The log-function takes two parameters: - $text: the activity you wish to log. - $user: optional…

Read more

Everything new in Laravel 5

Back in September Taylor Otwell said that Laravel 4.3 would be renamed to Laravel 5 to reflect a directory change and “other interesting initiatives”. Since that announcement the excitement for Laravel 5 has been building and “other interesting initiatives” turned into almost two dozen new features to help developers be more productive.
Eric Barnes made a nice list of the most notable new goodies in Laravel 5. The shiny new version of the framework will be released next week.

Read more

Generate image manipulations in a Laravel project

Earlier this month Glide joined The League of Extraordinary Packages. This package provides an easy way to generate image manipulations on the fly. Within a couple of hours I had integrated this wonderful package into both my company's legacy and current CMS.

The current CMS is based on Laravel. The Glide-integration is now available as a package on github: freekmurze/laravel-glide.

Installation

Nothing too fancy, you’ll have to:
  • use composer to pull in the package
  • install a service provider
  • install a facade
  • publish a config file
Read the specifics on Github.

Usage

Assuming you've got an image named `kayaks.jpg` in `app/storage/images` (this directory can be customized in the config file) you can use this code in a blade view:

<img src=&quot;{{ GlideImage::setImagePath('kayaks.jpg')->setConversionParameters(['w'=> 50, 'filt'=>'greyscale']) }}&quot; />

The function will output an URL to a greyscale version of kayaks.jpg that has a width of 50 pixels. As soon as the URL gets hit by your browser, the image will be generated on the fly. The generated image will be saved in app/storage/glide-cache (= the cache directory specified in the input file).

The generated URL will also be signed to prevent jerks from generating unwanted manipulations.

The setConversionParameters-function accepts an array with conversion options. You can take a look at the image API of Glide to see which options are available.

It's also possible to generate an image directly on the server:


GlideImage::setImagePath('kayaks.jpg')
    ->setConversionParameters(['w'=> 50, 'filt'=>'greyscale'])
    ->save($fileWhereImageManipulationMustBeSaved);

Read more

Using Elasticsearch in Laravel original

by Freek Van der Herten – 1 minute read

Elasticsearch is a lightning quick open source search server. It's java-based (but don't let that scare you) and can index and search documents. If you want to know more about it, watch this excellent talk by Ben Corlett. https://www.youtube.com/watch?v=waTWeJeFp4A For a recent Laravel project I had…

Read more

Automating Laravel deployments using Capistrano

Capistrano is a server automation and deployment tool. It makes a whole bunch of servers simultaneously perform actions. This could be deploying our application, or clearing their cache.

Capistrano tells each of our servers to pull the latest branch from Git, perform any necessary build steps, and deploy the application on itself. Setting up this process is what we'll be detailing.

https://www.airpair.com/laravel/posts/automating-laravel-deployments-using-capistrano

If you want to use something simpler, take a look at Deployer.

Read more

A Laravel webshop original

by Freek Van der Herten – 3 minute read

Earlier today Spatie, the company where I work, launched a webshop polkadots.be. When the project started one of the first choices that we had to make was if we were going to use an existing solution or build our own custom solution. For this project we took an extensive look at some existing…

Read more

Excel exports

Evan Miller makes the case for offering xls-exports instead of csv-exports.

Most people of your website’s users are also Excel users. When they export their data as CSV, they’ll probably just bring it into Excel first to have a look around. You should probably offer an explicit XLS export, and take it seriously.
http://www.evanmiller.org/please-offer-an-excel-export-option.html

An xls-file is capable of things that 'll never be possible in csv:

  • freezing the header row
  • formatting important cells
  • multiple sheets in one file
  • specify numer formatting
  • formulas
In the projects I've been working on I've been doing this for a couple of months. A nice Laravel package you can use is Laravel Excel.

This is how you export all values from a given repository that returns Eloquent models:


Excel::create($pathToFile, function($excel) {

    $excel->sheet('The sheet name', function($sheet) {
        $sheet->freezeFirstRow();

        $sheet->cells('A1:Z1', function($cells) {
            $cells->setFontWeight('bold');
            $cells->setBorder('node', 'none', 'solid', 'none');
        });

        $sheet->fromModel($this->yourOwnRepository->getAll());
    });

})->export('xls');

The result is an excel-file with the header row frozen and underlined and it's values in bold.

Read more

Add Two-Factor authentication to your Laravel application

Authy makes it easy to integrate two-factor authentication into your existing Laravel application. It's user-end implementation is versitile, offering support for both smart-phones and standard phones. Furthermore, implmentation with its API is easy and seamless. Finally, its analytics and data tracking can you provide insights into your users and how they interact with your application's authentication system.

This tutorial assumes that you have an Authy developer account (which can be created here ), an application (either testing or production), and your application's API key.

http://blog.enge.me/post/installing-two-factor-authentication-with-authy

Read more