How To: Validate an array of form fields with Laravel

Note: This tutorial is only relevant for Laravel 5.1 and lower. Laravel 5.2 has improved how this works.

If you’ve used Laravel’s form validation for any length of time, then you know it’s a powerful system. It makes the tedious task of validation very simple while still keeping the door open for complex rules.

In this tutorial, I want to show you a simple and easy way of validating forms that contain dynamic fields. A common use case for these types of forms is when you would like to allow a user to add more fields to a form.

Continue reading “How To: Validate an array of form fields with Laravel”

Farewell Snappy

A little over three years ago the team at UserScape had the idea to start a new light and simple helpdesk application that would later be named Snappy.

snappy-tear

Today it was announced that we will be shutting it down. For me, this is a sad day. I’ve spent countless hours on the project, but it’s deeper than that. When you and your team have built something from just an idea on a whiteboard, you have a passion for it that others can’t see. It’s your baby.

There is a popular mantra among programmers, “You are not your code” and it’s true. I don’t want to be defined by any code I’ve ever created, but the code and product as a whole are deeply personal. Saying this is the end is sad.

As with all failed projects all you can do now is look back objectively. Try to grow from the experience and keep pressing forward.

My thanks to everyone involved in the project. It was a fun ride.

Adding Custom Fonts to Mailchimps Drag and Drop Email Designer

MailChimp includes a neat drag and drop email designer, but it lacks the ability to customize your templates outside of just the basics. One such problem is the font choice. By default, it only includes a list of nine web safe fonts.

These fonts are your safest bet if you want to support as many email clients as possible, but I like to make my emails unique. In my opinion, a custom font gives the design a little extra pop and professionalism. In this tutorial, I want to outline a simple way of adding these to MailChimp’s included templates and still keep the nice drag/drop workflow.

Continue reading “Adding Custom Fonts to Mailchimps Drag and Drop Email Designer”

Marcus Zarra on the dangers of misinformation:

As developers, we are frequently using the internet to help us solve issues. We run across an error code, a crash, or another type of problem and we usually go to the internet. With the vast amount of knowledge that is available, and the incredible search engines that we have at our disposal, it is pretty easy to find someone else who has already run across the issue. Sites like StackOverflow make it even easier to find other people who have experienced the issue we are running across.

The issue is that we don’t really know if the information being shared with us is accurate. The author of that post, or response, may be guessing. They may have found a hack or workaround that kind of works, for now. They may be completely wrong and are treating a symptom as the actual problem.

I agree with the premise of this whole article. It’s so hard in the ever changing world of tech to know what is still accurate and what isn’t. Just today I had to update a tutorial I wrote back in September. The basics of it was the same, but the dependencies changed enough to make it not work and in turn cause frustration for readers.

I’ve noticed in my own searching habits, that when looking for tutorials I always look for the published date. If it’s over six months old chances are it isn’t even accurate.

Gulp, Bower, and Bootstrap SASS Example App

A few months back I created a tutorial on Setting up Gulp, Bower, Bootstrap Sass, & FontAwesome. If you had problems with the tutorial I’m sorry. Apparently the gulp-ruby-sass npm module I used is undergoing some changes causing the SASS to error out and never compile. I have updated that post to recommend sticking with version ^0.7.1 until v1 stables out.

I’ve also created a GitHub repo with everything setup. This way you can see the exact versions of dependencies I used in the tutorial.

What I do find odd is I had a similar problem with Laravel Elixir a few weeks back. It uses node-sass but something must be going on with the development of both of these plugins. Hopefully, it will all be sorted out and I can stop pulling out my hair.

Call Laravel Artisan Seed From Your Code

There are certain times when using Laravel that you would like to migrate and seed the database. Typically this is done via the Artisan command line tool with:

php artisan migrate --seed

You can also call this in your code with the following:

Artisan::call('migrate', ['--seed' => true]);

Nice and simple but the second parameter always trips me up.

How to setup WordPress with Forge and DigitalOcean

Laravel Forge is a service that handles creating servers on popular cloud hosting providers. I use it to host my WordPress sites with DigitalOcean and to handle auto deployments from a git push.

Installing WordPress on a cloud server you need to plan for failure. Typically there is no guarantee that you will not wake up one morning and find the server just gone. I’ve personally ran into that with AWS in the past and now I always plan for it. Continue reading “How to setup WordPress with Forge and DigitalOcean”

8 Laravel Packages For Your Next Project

The best way to spread Christmas Cheer, is singing loud for all to hear.

Buddy The Elf

Since my singing is terrible, I’m going to spread developer cheer by posting my eight favorite Laravel packages of 2014. These are in alphabetical order.

Carbon

This is included in the Laravel core but it’s worth mentioning because of how much I use it. Dealing with dates has never been easier.

Debugbar

All the behind the scenes information you need to ensure your app is running smoothly and efficiently.

Envoy

Envoy allows you to run SSH commands on a remote system. I use it for everything from local tasks to deployments.

Laravel DomPDF

This makes creating PDF’s nice and simple by wrapping the DomPDF library in a Laravel familiar syntax.

Laravel Generators

Speed up your workflow with these time-saving generators. It includes commands for almost everything.

Laravel IDE Helper

If you use PhpStorm then this package is a must have. I use it on all my projects and it makes your IDE play nicely.

Intervention

Every project seems to have to deal with image uploads in one form or another. Intervention makes image uploading and processing a breeze.

Parsedown

I use this whenever I need to parse markdown. It is fast, consistent, and easy to use.


All the projects I worked on this year, Snappy and one or two side projects, were really focused and I didn’t have a chance to implement a lot of the other packages. Hopefully, that changes over the next year because the community has created so many. I’d love to have the time to explore all of them.

Thanks to everyone who created in 2014!

Did I miss your favorite? Share in the comments.

WordPress Total Words Counter

As the year is coming to a close a lot of sites are creating year in review style posts. I love these because I find it interesting how my stuff compares to them and I try to find little nuggets of information on what I should be doing better.

Alex King has been doing this for the past 9 years and has created a little gist for generating a lot of useful stats.

To take this a step further I wanted to count the total words I published for the year and I put together a little script if you’d like to do the same:


<?php
$words = 0;
$posts = query_posts([
'posts_per_page' => –1,
'year' => '2014',
]);
foreach ($posts as $post) {
$words += str_word_count($post->post_content);
}
echo 'Total Words: '. number_format($words);
?>

Granted this method is simple and the php function str_word_count is not entirely accurate. If you’d like to get fancy a Word Stats plugin does exist but I found that it wouldn’t work at all with the current version.

I came across this site and it says my first pull request was four years ago to the Fuel PHP framework. As far as I remember this isn’t my real first pull request. Just the first on GitHub.

Back then I was big into CodeIgniter and they either used HG or Git, but the project was on Bitbucket. So I’m sure my true first would have been around a year or so earlier.

It is interesting thinking back and seeing how much has changed in the PHP landscape since then. Four years ago composer didn’t exist, Laravel didn’t exist, as well as many of the packages we rely on today.

Imagine all the changes that will happen over the next four.

Minimal Genesis: New WordPress Theme

I’m happy to announce my first ever WordPress theme which is modeled after a previous design of this site. It’s simple, clean, with a focus on typography and includes several post formats to make your site unique.

Theme Example
Theme Example

The theme came to life earlier this year when I wanted to rebuild this site. I am constantly changing the design and finally decided that I had spent way to much time looking for a perfect theme. All the theme markets focus on designs with lots of images and complexity. I wanted to go back to basics and have something that would look nice without images.

Minimal Genesis Theme Features

This is a child theme for the popular Genesis framework. The parent theme is a requirement and it is commercial. Genesis is widely used and has tons of nice features for your site.

This theme features everything included with Genesis as well as:

  • Post formats – Linked, Quote, Image, and Standard
  • All WordPress common features
  • Search Engine Friendly
  • Clean and Minimal

Post Formats

I view personal blogging as a journal. As such your theme should have the ability to support long-form posts, quotes, and links.

Link Post

Link Post
Link Post

I believe a link post should have the title linked to the actual site you are writing about. You can set this style up by selecting the “link format” in the post sidebar and then adding an extra field named “link” with the value of the url. Here is a screenshot of the custom field setting:

Quote Post

Quote Post
Quote Post

This is an example quote style post format. To set this up select the quote format in the post edit sidebar. Then have the quote as the first part of the content. To style the author name set the name to bold or em.

Featured Image

Featured Image
Featured Image

Featured images are supported and will appear above the title and be the full size of the post box.

Buy It Now

If you like this theme you can buy it now at Creative Market. If you’d like to give it a test drive check out the theme demo.

JavaScript Helper for Triggering Stripe Failures

Lately I’ve had to integrate Stripe a few times and I keep having to visit their test card page over and over to copy and paste failed cards. Today I finally had enough and threw together a little helper that you can add to a Laravel blade file.


<script>
@if (App::environment('local'))
var $el = $("#card-number");
window.stripeData = {
valid: function() {
$el.val('4242424242424242');
},
successAddressFail: function() {
$el.val('4000000000000028');
},
successZipFail: function() {
$el.val('4000000000000036');
},
fail: function() {
$el.val('4000000000000002');
},
failNumber: function() {
$el.val('4242424242424241');
},
failCVC: function() {
$el.val('4000000000000127');
},
failExpired: function() {
$el.val('4000000000000069');
},
failProcessingError: function() {
$el.val('4000000000000119');
}
}
@endif
</script>

With this when you view the credit card form you can open console and type stripeData. and have autocomplete of whatever failed message you want to test for.

I know this is super simple but it helped me so I think it’s worth sharing.

The Simplest Way To Use Laravel Blade And AngularJS Together

By default AngularJS and Blade conflict with the way variables are called. Both use a double curly bracket {{ var }} syntax. There are a few workarounds such as changing Angular’s or Blade’s delimiters but an easier method is available.

Inside blade prefix Angular echo variables with the at “@“ symbol. Here is an example:


<li ng-repeat="phone in phones | filter:query | orderBy:orderProp">
<span>@{{phone.name}}</span>
<p>@{{phone.snippet}}</p>
</li>

This will prevent blade from parsing it but will be correct when sent to the browser.

Nice and simple!

PhpStorm Tip – Keymap Abbreviations

I made the switch to PhpStorm back in January and every week I learn new tips and tricks to help me use the IDE. One issue I have is that I constantly forget keyboard shortcuts even though I only use a few. So I want to show a quick tip to make these easier to remember.

One workaround for not having to learn them is to use the “search anywhere” feature. You can bring it up with “shift shift” and search any part of your code, interface actions, and tool windows. It’s powerful!

This feature is really great but it also has a downside. I typically think of actions and windows in a different context than their actual name. PhpStorm planned for users like me and it includes a nice way of assigning abbreviations to the keymap.

Let me show how great this is.

Go to settings -> apperance & behavior -> keymap.

Then you can search for a command and right click to assign an abbreviation.

Here is an example where I set “a” to the abbreviation for annotate:

phpstorm-abbreviation

Now with that set you can bring up the search anywhere and just enter the letter a, which causes it to be the first result:

phpstorm-search-abbreviation

If you have trouble remembering keyboard shortcuts or want to speed up common tasks give this a try.

Here are the ones I’m currently using:

  • a – git annotate
  • v – split vertically
  • t – terminal

Now that CodeIgniter development has been taking over by BCIT a lot of people are wondering what will happen with the framework. I’m still not really sure what the future holds but I’m happy to see them put together an interim council. A lot of names I remember from back in my CodeIgniter days and also some friends.

Here is a list of the current members:

  • Andreas Pfotenhauer
  • Andrey Andreev
  • Ben Edmunds
  • David Wosnitza
  • Jim Parry
  • Lonnie Ezell – Council

Above all I’m happy that Andrey, David, and Ben are on this. All stand up guys that have done a lot for the framework over the years.

Rebuilding Wardrobe – Sabbatical

As I’m sure you are aware I’ve taken a little sabbatical from the rebuilding Wardrobe series. Before I started the series I asked Chris Pitt for some advice since he has done it before. He said:

The rebuilding series’ are a huge load. Anything upsets their schedule.

That did in fact happen and put me way off schedule.

Also a minor issue is I am building this with Laravel 5 which is just in alpha. So keeping up with changes in it and developing a new app was too time consuming. With all that I’m going to take a few more weeks off and plan to resume in November.

I appreciate all the interest in the series and I hope it continues to go well once I resume.

Rebuilding Wardrobe: Week 4

In this weeks Rebuilding Wardrobe series I started working on the list of posts. That sounds easy right? Grab all the posts from the database, loop them, and print them in table rows. But in our crazy world of web development it’s never that easy. One of the fields that should be included is the published date and that means I have to account for timezones. Yuck! Continue reading “Rebuilding Wardrobe: Week 4”

This is an old but epic post discussing the pros and cons of each of these frameworks. I’ve been using Backbone heavily over the past two years and this quote really rings true to my experience:

I think Backbone is not a framework, when using Backbone you have to build a framework from the primitives it provides. This can be powerful or a burden and it mostly comes down to how much control you care to have.

In the end Ghost decided to go with Ember and the comments in the GitHub issue makes strong arguments for all three.