Laravel 4 Notification System Tutorial – Part 4; Grouping Notifications

Laravel 4 Notification System Lesson Plan

  1. Part 1: Setting up the Database and Models and Sending Notifications
  2. Part 2: Retrieving Messages and their Object contexts
  3. Part 3: Preparing to Group Notifications
  4. Part 4: Grouping Notifications

Grouping Notifications in our Laravel 4 application

We’ve arrived at the conclusion of our Laravel 4 Notification series and in this lesson, we’ll be wrapping it up by demonstrating one method of grouping Notifications stored in a MySQL Database.

The method I’m using for Grouping Notifications in this tutorial relies entirely on MySQL – all of the heavy lifting is done by the database and I’ll let you guys debate whether or not that’s a good thing or a bad thing!

In a nutshell, we group notifications by there Type and Type ID and use some MySQL aggregate functions and string manipulation functions to modify our records.

Continue reading Laravel 4 Notification System Tutorial – Part 4; Grouping Notifications

Laravel 4 – Argument 1 passed to validateCredentials() must be an instance of UserInterface

If you’ve run into the following Laravel 4 Authentication Error:

Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Auth\UserInterface, instance of User given

Chances are, you’re not implementing the ‘Illuminate\Auth\UserInterface’ in your ‘User’ model.

Continue reading Laravel 4 – Argument 1 passed to validateCredentials() must be an instance of UserInterface

Laravel 4 Notification System Tutorial – Part 3; Preparing to Group Notifications

Laravel 4 Notification System Lesson Plan

  1. Part 1: Setting up the Database and Models and Sending Notifications
  2. Part 2: Retrieving Messages and their Object contexts
  3. Part 3: Preparing to Group Notifications
  4. Part 4: Grouping Notifications

Grouping Notifications

This had been requested by a couple of readers and I feel if anyone is going to use this system, it’s a very nice feature to have. In this tutorial, I’ll do my best to explain one way of Grouping Notifications using the foundations we’ve laid in Part 1 and Part 2.

Part 3 was initially going to cover notification grouping in it’s entirety, however, due to the size of the tutorial, I’ve decided to split it over 2 parts – part 1 will be the preparation and part 2 will be the heavy lifting.

Continue reading Laravel 4 Notification System Tutorial – Part 3; Preparing to Group Notifications

Laracasts Test Dummy composer problem – requires illuminate/support ~5.0

If you are experiencing the following error whilst trying to install Laracasts Test Dummy plugin via composer;

laracasts/testdummy dev-master requires illuminate/support ~5.0

Chances are, you are still using Laravel 4. To get around this error, you simply need to use an earlier version of Test Dummy in your composer.json file:

    "require-dev": {
        "laracasts/testdummy": "1.1.*"
    }

Changing default timestamp names in Eloquent models, Laravel 4

I was recently tasked with building a new Laravel 4 application which had to closely integrate with an existing application – the only problem was, there was no API exposed for the existing application and no way of getting one created. Despite our warnings and best efforts to persuade against it, we had to maintain two database connections in the new application, one for the old site and one for the new site. When adding a new record to the new site, we also had to push a reference to the old site, however, the timestamps for `created_at` and `updated_at` were `created` and `modified` in the old application.

Since we had a namespaced set of Eloquent models for the old database, dealing with timestamps for old database meant had to override the Laravel defaults for those field names.

After some digging in the code, this can be achieved by simply adding the following code to your Model:

    /**
     * The name of the "created at" column.
     *
     * @var string
     */
    const CREATED_AT = 'created';

    /**
     * The name of the "updated at" column.
     *
     * @var string
     */
    const UPDATED_AT = 'modified';

Laravel 4 Environment Specific Package Config

Modern development is great. If you are implementing a service, or a chunk of functionality, chances are, someone has already done it and made it available.

In PHP development, we are lucky enough to have Composer and a plethora of packages available on packagist.com ready to drop straight into our own projects.

Sometimes when installing packages, you need the ability to tweak the package configuration depending on which environment the code is being run on. One example of this is when using the Stripe.com SDK – you will likely have an API key for your sandboxed test account and another API key for production.

In Laravel 4, this is really easy – simple create your configuration in folders which follow this format:

app/config/packages/<author>/<package>/development/config.php
app/config/packages/<author>/<package>/production/config.php

Remember and switch out and to suit your needs – this should match the author and package as it’s installed in your vendor folder.

Laravel 4 Twilio Tutorial – Receiving SMS Text Messages with PHP

Part 2 of the Laravel 4 Twilio Tutorial will focus on handling incoming messages to our application.

Tutorial Plan

  1. Sending SMS Text Messages with PHP using Laravel 4 and Twilio
  2. Receiving SMS Text Messages with PHP using Laravel 4 and Twilio
  3. Making Voice Calls with PHP using Laravel 4 and Twilio
  4. Handling Voice Call User Input with PHP using Laravel 4 and Twilio

Handling incoming SMS Text Messages with Laravel and Twilio

This is actually very simple to do. The first step is to access twilio.com and configure your applications Messaging Request URL. This can be any URL you like; it will be the URL Twilio makes a POST request to when one of our phone numbers receives a text message, e.g. yourdomain.com/sms/incoming.

Continue reading Laravel 4 Twilio Tutorial – Receiving SMS Text Messages with PHP

Laravel 4 Notification System Tutorial – Part 2; Reading Notifications

Laravel 4 Notification System Lesson Plan

  1. Part 1: Setting up the Database and Models and Sending Notifications
  2. Part 2: Retrieving Messages and their Object contexts
  3. Part 3: Preparing to Group Notifications
  4. Part 4: Grouping Notifications

Reading Notifications

Part 2 of our tutorial is all about reading our Users notifications. Before we march on, let’s have a think about what data want to extract from our notifications table.

  • A count of our unread notifications
  • A list of our unread notifications
  • Retrieving the object from our notifications

Continue reading Laravel 4 Notification System Tutorial – Part 2; Reading Notifications

Laravel 4 Notification System Tutorial – Part 1; Sending Notifications

One of the most common features in most modern web applications is a notification system; the ability to notify a User following an event in your system. This can be done in lots of different ways and throughout this series, I will demonstrate one way of creating a Laravel 4 Notification System.

Laravel 4 Notification System Lesson Plan

The plan for this series (subject to change) is:

  1. Part 1: Setting up the Database and Models and Sending Notifications
  2. Part 2: Retrieving Messages and their Object contexts
  3. Part 3: Preparing to Group Notifications
  4. Part 4: Grouping Notifications

Schema

Let’s begin by thinking about a possible schema to start of our Laravel 4 Notification system. It’s always beneficial to think about how your data will be represented in your data store before you even touch a line of code.

Continue reading Laravel 4 Notification System Tutorial – Part 1; Sending Notifications