Posts

What are the New Features in Laravel 5.5?

Image
Version 5.5 of Laravel is officially released! This release is jam-packed with goodies and improvements, here’s a quick summarizing the highlight features. 1. New Route Methods introduced in Laravel 5.5 Laravel 5.5 shipped a couple of convenient shortcuts to the Laravel Router class that eliminates the need for creating a controller or closure only to return a simple view or redirect. If you missed them in the release notes, let’s look at them briefly, they are sure to simplify your code and remove a couple of files. The Route::view method The Route::view method eliminates the need for routes that only need a view returned. Instead of using a controller or a closure, you can define a URI and a path to a view file: // resources/views/pages/about.blade.php Route::view('/about', 'pages.about'); You can also pass in an array of variables that will be passed to the view: Route::view('/about', 'pages.about', ['year' => date('...

Laravel Homestead v6.6.0 Released – Latest Update

Image
Homestead Introduction Laravel strives to make the entire PHP development experience delightful, including your local development environment. Vagrant provides a simple, elegant way to manage and provision Virtual Machines. Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes! Homestead runs on any Windows, Mac, or Linux system, and includes the Nginx web server, PHP 7.1, PHP 7.0, PHP 5.6, MySQL, PostgreSQL, Redis, Memcached, Node, and all of the other goodies you need to develop amazing Laravel applications. Release v6.6.0 Laravel Homestead v6.6.0 was released over the weekend, most notably adding self-signed wildcard SSL certificates a...

A Package for Laravel Blade Extension Classes

Image
Laravel created a Blade Extension package that allows you to register Blade extension classes in the service container that automatically get registered with the Blade compiler. You can also easily create new Blade extension classes with the provided  php artisan make:blade  command (auto-registered package commands FTW). Laravel Blade Extension Classes The concept isn’t revolutionary by any means, but user like how it organizes their project-specific blade extensions into service container classes. Let’s say, for example, that you have some custom directives around working with a shopping cart. Here’s a quick example of how it might look using Blade Extensions package: <?php namespace App \ Blade ; use BitPress \ BladeExtension \ Contracts \ BladeExtension ; class CartExtension implements BladeExtension { public function getDirectives () { return [ 'cartcount' => [ $this , 'getCartCount' ] ]; } ...

Laravel Model Caching

Image
You’ve probably cached some model data in the controller before, but here’s we like to show you a Laravel model caching technique that’s a little more granular using Active Record models. Using a unique cache key on the model, you can cache properties and associations on your models that are automatically updated (and the cache invalidated) when the model (or associated model) is updated. A side benefit is that accessing the cached data is more portable than caching data in the controller, because it’s on the model instead of within a single controller method. Here’s the gist of the technique: Let’s say you have an  Article  model that has many  Comment  models. Given the following Laravel blade template, you might retrieve the comment count like so on your  /article/:id  route: <h3>$article->comments->count() {{ str_plural( 'Comment' , $article->comments->count())</h3> You could cache the comment count in the contro...