Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Stitcher.io:
Laravel view models
Sep 24, 2018 @ 12:27:50

On the Sticher.io site a new tutorial has been posted introducing you to Laravel view models. This functionality allows you to remove view-only logic from other parts and isolate it for transformation.

View models are an abstraction to simplify controller and model code. View models are responsible for providing data to a view, which would otherwise come directly from the controller or the model. They allow a better separation of concerns, and provide more flexibility for the developer.

In essence, view models are simple classes that take some data, and transform it into something usable for the view.

The post starts with some of the basics behind the "view model" design pattern and jumps in to an example for a blog site. In it, the code pulls in the category listing that's needed to display the page, removing the need for it to be in the controller code. It also includes the addition of custom logic to the model and the refactoring that can help move the logic into it. The tutorial also includes a section covering some of the "niceties" that can be added including passing it directly to the view method, returning it as JSON and returning individual properties as JSON.

tagged: laravel tutorial viewmodel designpattern example introduction

Link: https://stitcher.io/blog/laravel-view-models

TJ Miller:
Verifying Laravel Version Compatibility
Sep 24, 2018 @ 10:45:58

TJ Miller has written up a post for his site sharing a method he's created to verify the compatibility of a package in Laravel based on the version of Laravel installed.

I’ve been working with Honeybadger to build a new set of PHP integrations. I would like to write more about that soon, however, I feel like I’ve stumbled across something that could be useful to others. I wanted to share it as soon as I could.

For the Laravel package, I was aiming for Laravel 5.5 and newer support as it is the latest LTS version. [...] In hindsight, I don’t think that I actually ever tested it against a 5.5 install. I relied on the CI process to make those verifications for me.

[...] As Laravel 5.7 is now out, I needed to add support to both the package’s composer configuration and verification in CI. [...] Now that I am supporting three versions I felt that I needed a more specific way of verifying compatibility with different versions of Laravel.

He shares his initial version of his Travis-CI configuration, running tests on PHP 7.1 and 7.2 with the prefer-lowest flag. In order to make it easier, he updated this based on what he'd seen in other packages: adding a matrix that runs PHP 7.1 through 7.3 against versions 5.5.x, 5.6.x and 5.7.x to ensure compatibility across all variations. His resulting build looks something like this.

tagged: verify laravel version compatibility travisci multiple language framework

Link: https://blog.tjmiller.me/verifying-laravel-version-compatibility

Pineco.de:
Inviting Users with Laravel’s Singed URLs
Sep 10, 2018 @ 11:56:57

On the Pineco.de site they've posted a tutorial for the Laravel users out there showing how to use the framework's "signed URL" functionality to create invite links for your application.

We can handle user invitations easily with the old and good database way. We create an invitation, store it with a unique token, then email it to the user. If the user uses the link, we can delete it from the database and that’s all. Now let’s give a try to Laravel’s signed URLs to handle a database-less solution.

The article starts by explaining what the "signed route" functionality is and how to generate then using the URL helper. It also shows how to use the "signed" middleware to validate the signature provided on the request. Finally, it shows how to configure, send and use the hashes to handle user registration.

tagged: laravel signed url tutorial registration

Link: https://pineco.de/inviting-users-with-laravels-singed-urls/

Laravel News:
Laravel 5.7 Guest User Gates
Sep 06, 2018 @ 10:49:45

On the Laravel News site they highlight a change in the way that the "gates" handling works in the v5.7 release of the popular framework. In this change you can now allow "guest" users into certain parts of your system.

In Laravel 5.6 and below authorization gates and policies automatically return false for unauthenticated users. New in Laravel 5.7, you can now allow guests to go through authorization checks by using a nullable type-hint or setting the default value as null:

[...] By using a nullable type hint the $user variable will be null when a guest user is passed to the gate, and you can then make decisions about authorizing the action. If you allow nullable types and return true, then the guest will have authorization.

The post includes a code snippet showing how to put it to use and the resulting 403 page they would get otherwise. You can find out more about other new features of Laravel v5.7 in this other article.

tagged: laravel gate user tutorial nullable feature framework

Link: https://laravel-news.com/laravel-5-7-guest-user-gates-policies

Laravel News:
Manage Maintenance Mode in Laravel Nova
Sep 04, 2018 @ 11:24:52

On the Laravel News site they've posted a quick tutorial showing how to add in "maintenance mode" management functionality into Laravel Nova, the recently released administration panel product for Laravel-based applications.

If for some reason you’ve been on another planet (see what I did there?), Laravel Nova is Now Available and the community has been rather busy building open-source tools around Nova.

One of those open-source tools is by David Piesse, who created a Laravel Nova extension that allows you to manage the maintenance mode of your application from Nova

The package to add the functionality is easily installed via Composer and integrate via a service provider. This then adds a new toggle to the administration panel's UI to enable or disable maintenance mode (as well as an icon showing the current status).

tagged: maintenance mode laravel laravelnova panel package tutorial

Link: https://laravel-news.com/manage-maintenance-mode-in-laravel-nova

CodeWall:
Use Laravel Eloquent Query Builder In Any PHP Project
Sep 04, 2018 @ 10:30:49

On the CodeWall.co.uk site there's a new tutorial showing you how to use Eloquent outside of Laravel applications thanks to its "capsule" functionality. Eloquent is an ORM layer that's a part of the Laravel framework and makes it easier to work with records and sets of data from your database.

OWASP (Open Web Application Security Project) is a project that notes down the current threats to a web application. And I have been researching on their site and I have found this similarity in their 2010, 2013 and 2017 report that, SQL Injection or any other type of Injection is number 1 on this list, every time.

And that’s a part to worry.

This can cause you to get out of business, so this is pretty serious and your organisation should take care of the this issues and prevent yourself from it.

The tutorial starts with a brief introduction of what SQL injection is including some example SQL to show how the injection happens. It then covers how to prevent this issue with base PHP code (no framework or package) using prepared statements and bound parameters. Eloquent takes care of this for you and provides a lot of other handy features. The article goes on to show:

  • how to install the Eloquent packages with Composer
  • the code to create the "capsule" that's used as a bridge into the Eloquent code
  • the creation of migrations for two tables: users and posts
  • how to make models for these two tables

The post wraps up with a look at using these models to create a new user and post record using the ORM interface rather than manual SQL statements.

tagged: tutorial laravel eloquent query orm introduction model capsule

Link: https://www.codewall.co.uk/use-laravel-eloquent-query-builder-in-any-php-project/

Nick Basile:
Improving Our Laravel Nova CRM
Aug 28, 2018 @ 12:05:31

On his site Nick Basile has a new post sharing some of the ways you can improve an installation of Laravel Nova (the administration dashboard) for a CRM. This latest tutorial is the second part in his series (part one is here).

In my last post, we started building a simple CRM using Laravel Nova. It was pretty complete when we left it, but I think we can add a few more features and explore the rest of what Nova has to offer. In this walkthrough, we'll take a look at how to use Nova's Actions and authorization.

He walks through the additions and improvements he's added to his Nova dashboard:

  • an Action that automates the updating of a lead's status
  • additional authorization checks using policies for model delation

Code is included for each of these along with a summary that walks you through the creation and integration process.

tagged: laravelnova laravel nova administration improvement crm tutorial

Link: https://nick-basile.com/blog/post/improving-our-laravel-nova-crm

Stitcher.io:
Eloquent MySQL views
Aug 28, 2018 @ 10:38:54

On the Sticher.io blog Brent has written up a post covering the use of MySQL views in Eloquent, the database ORM that's included with the Laravel framework.

MySQL views are a way of storing queries on the database level, and producing virtual tables with them. In this post we'll look at why you want to use them and how they can be integrated in Laravel with Eloquent models.

If you're already convinced of the power of MySQL views, or just want to know how to implement them in Laravel, you're free to skip ahead.

For those not familiar with the concept of "views" in MySQL, he spends a little time explaining what they are and what benefits they bring to the table. This includes a code example of a migration to create one and how something similar could be achieved with event hooks on a Laravel model. He then gets into the use of the views with Laravel, refactoring a more complex SELECT query into a view and creating/removing it using the same migration methods as any other table in the database.

tagged: eloquent mysql view tutorial introduction database laravel

Link: https://stitcher.io/blog/eloquent-mysql-views

CoderWall:
The Laravel Admin Panel That You Need
Aug 27, 2018 @ 09:21:04

On the CoderWall site they've posted a tutorial that's a sort of reaction to the recent Laravel Nova administration dashboard release. In it they point out another project, the Laravel Admin Panel (LAP) that handles a lot of the same kind of functionality.

I have been working on this product on opensource for about 8 months now, and the project has become quite successful. People are actually using it and we are making our goal to make it more developer friendly. [...] According to my experience with people who have used our admin panel and its feature to create a module instantly, they are aloof of the details beneath that architecture and are constantly in need of help if anything goes wrong.

If new developers are made to use some super smart software which just creates everything for them, they are just not very aware of the happenings and end up not knowing anything of how the project works.

The post introduces the project and what kind of functionality it provides including:

  • user/role/permissions management
  • "page" management
  • menu management

...and their "star of the show", the Module Boilerplate Generator that allows for the quick and easy generation of all code required to add a new module to the application (models, controllers, request handling, views, migrations, etc). You can find more information on the GitHub repository for the project.

tagged: laravel administration panel introduction lap project opensource

Link: https://www.codewall.co.uk/the-laravel-admin-panel-that-you-need/

Laravel News:
Laravel Nova is Now Available
Aug 23, 2018 @ 09:15:15

As is mentioned in this new post from the Laravel News site, the latest product in the Laravel ecosystem - Laravel Nova - is now available for purchase.

We expected a Nova release at Laracon EU 2018 around the same time that Laravel 5.7 is due out. In an unexpected move (and in light of many people wanting to get their hands on Nova early) Taylor decided to ship Nova.

[...] Laravel Nova works with both Laravel 5.6 and the upcoming release of Laravel 5.7, so rest assured that it works with the latest stable version.

So what's Nova? It describes itself as "a beautifully designed administration panel for Laravel. Carefully crafted by the creators of Laravel to make you the most productive developer in the galaxy." It provides most of the functionality you'd expect from an administration panel including user management, model (resource) details, metrics and the ability to extend via custom functionality. The per-site pricing is relatively affordable and has two levels: Solo for $99 and Pro for $199.

tagged: laravelnova laravel administration panel framework product release

Link: https://laravel-news.com/laravel-nova-release