Notifications: Email

Notifications in Laravel 5.3 are incredible. Create a single a notification class, and then designate one or more distribution channels to use – such as email, SMS, Slack, and more. I think you’ll really like this new component, so let’s take a few episodes to review all of its functionality. We’ll start with basic email notifications, and review the nice, fluent API for rapidly building up messages.
Source: Laracasts

Laravel Notifications – Easily send quick updates through Slack, SMS, Email, and more

Laravel Notifications is an all new feature coming to Laravel 5.3 that allows you to make quick notification updates through services like Slack, SMS, Email, and more.

Let’s see how easy it is to build and send a notification using this new feature:

class NewPost extends IlluminateNotificationsNotification
{
    public function __construct($post)
    {
        $this->post = $post;
    }

    public function via($notifiable)
    {
        return ['database'];
    }

    public function toArray($notifiable)
    {
        return [
            'message' => 'A new post was published on Laravel News.',
            'action' => url($this->post->slug)
        ];
    }
}

All you need to do now is to send the notification to the selected users:

$user->notify(new NewPost($post));

Creating Notifications

Laravel 5.3 ships with a new console command for creating notifications:

php artisan make:notification NewPost

This will create a new class in app/Notifications, each notification class contains a via() method as well as different methods for building notifications for different channels.

Using the via() method you can specifying the channels you’d like this particular notification to be sent through, check this example for the official documentation website:

public function via($notifiable)
{
    return $notifiable->prefers_sms ? ['sms'] : ['mail', 'database'];
}

The via method receives a $notifiable instance, which is the model you’re sending the notification to, in most cases it’ll be the user model but it’s not limited to that.

Available channels are: mail, nexmo, database, broadcast, and slack.

Formatting Email Notifications

You can format how notifications are sent through different channels, for instance, let’s take a look at formatting a mail notification:

public function toMail($notifiable)
{
    return (new MailMessage)
                   ->subject('New Post!')
                ->line('A new post was published on Laravel News!')
                ->action('Read Post', url($this->post->slug))
                ->line('Please don't forget to share.');
}

This will create a mail message using a nice built-in responsive template that you can publish using the vendor:publish console command.

The notification system will automatically look for an email property in your model, however, you can customise this behaviour by defining a routeNotificationForMail in your Model and return the email address this Model will be contacted on.

Formatting Nexmo SMS Notifications

Same as in the case of an email notification, you need to define a toNexmo method in your notification class:

public function toNexmo($notifiable)
{
    return (new NexmoMessage)
        ->from(123456789)
        ->content('New post on Laravel News!');
}

In the case of Nexmo notifications, laravel will look for a phone_number property in the model. You can override that by defining a routeNotificationForNexmo method.

You can set a global from number in your Nexmo configuration file, that way you won’t have to provide a from number in each notification.

Formatting Database Notifications

To Format a database notification you may define a toDatabase method:

public function toDatabase($notifiable)
{
    return new DatabaseMessage([
        'message' => 'A new post was published on Laravel News.',
        'action' => url($this->post->slug)
    ]);
}

To start using the database channel you may read the full documentation on the official website.

Sending Notifications

You can send notifications using the notify() method on your model, this method exists on the Notifiable trait which you’ll need to add to your Model.

$user->notify(new NewPost($post));

You can also use the Notification facade, this will allow you to send notifications to multiple notifiables at the same time:

Notification::send(User::all(), new NewPost($post));

Queueing Notifications

You can easily queue sending notifications by using the ShouldQueue interface on the Notification class and including the Queueable trait.

<?php

namespace AppNotifications;

use IlluminateBusQueueable;
use IlluminateNotificationsNotification;
use IlluminateContractsQueueShouldQueue;

class NewPost extends Notification implements ShouldQueue
{
    use Queueable;
}

Source: Laravel News

DreamFactory – Turn any database into an API Platform (Sponsor)

DreamFactory auto-generates a rich API platform from nearly any SQL or NoSQL database. In addition to automatically generating REST endpoints for data and schema, DreamFactory offers parameters for complex filters, virtual foreign keys, aggregation, and much more.

df-main-infographic-700px

Built on the Laravel framework, DreamFactory is feature-rich backend solution for real world application development. Instant APIs let you build and iterate fast and the Apache license allows for wide distribution.

healthcare-app

DreamFactory Gold is an enterprise solution for fully realized developer ecosystems offering granular user and resource management along with exceptional support direct from our engineering team.

Recent blog posts:

Try it out now on our free hosted system or dig deeper into the possibilities with robust documentation and sample apps for a wide array of front-end destinations.

Source: Laravel News

Toggle Pivot Table Records

In Laravel 5.3, you’ll find a new toggle() method on all belongsToMany relationships. This solves the issue of needing to delete a pivot table record if it exists, or adding it if it doesn’t. As an example, consider needing to toggle a user’s "like" status for a post.
Source: Laracasts

How Do I Fetch the Most Recent Reply’s Username

So you have a single post model, and you want to fetch the username of the most recently published comment. How exactly do we do that? Well, I’ll show you a few techniques you might use, ranging from adding a hasOne relationship, to leveraging the law of demeter, to applying simple joins.

Thanks so much to Wadday Hassan for the question. If the rest of you have any questions that could be answered in video-form, tweet your question and add the hash tag, #helpMeLaracasts.
Source: Laracasts

Laracon EU – Interview with speaker Freek Van der Herten

This year’s Laracon EU has a fantastic speaker lineup including twenty-two speakers from all across the world. Tickets are still available and it’s one you will not want to miss.

Freek Van der Herten (@freekmurze) is one of those speakers and he graciously took a break from releasing new packages to allow me the opportunity to ask him a few questions about his talk and the conference experience.

Is this your first Laracon EU?

No, I’ve been the last year’s edition as well and I had a blast there. To be honest it was the best conference I’ve ever been to. The people, the talks, the venue, … it was incredible. The bar is set very high for this edition.

How far away are you from Amsterdam?

I live in Belgium, which is a neighboring country of The Netherlands. From my hometown, Antwerp, Amsterdam is only 2 or 3 hours away by train.

Your Laravel backup package seems to be popular is that what you are going to be giving a talk on?

I’ll dedicate quite some time of my talk to introducing the package. I’ll demonstrate what it can do. Since we’re going to be in a room full of developers I’ll also show the inner workings of the package. But aside from that I’ll also touch on the pitfalls and best practices regarding backups in general and highlight some good backup solutions.

Should everyone be using a backup system outside of what hosting companies provide?

Unless you have a dedicated ops person/team that takes care of backups, you as a developer should definitely take care of your own backups in addition to what your hosting company provides. Take DigitalOcean for example: they provide backups, but they only take a snapshot once a week. So if you solely rely on their backups you could potentially lose data for several days. Most cloud providers store their backups in the same datacenter as your servers. So if the datacenter is down, the backups are unavailable. These are all good reasons to take care of backups yourself.

What other talk are you most excited about?

Sorry, it’s just too difficult to name a single speaker here. I’m looking forward to seeing two my fellow Belgians speaking: Hannes Van de Vreken will talk about cool stuff you can to with the IoC container, Mattias Geniar will explain how Varnish can be used to speed up a site. Also, high on my list is Gabriela D’Avila who will talk about making the most with MySQL 5.7

Any other words of encouragement for those coming to Laracon?

I’m a big fan of uncon’s at conferences and I’m happy this edition of Laracon EU will have one. If you’re not familiar with an uncon, it’s just a room at a conference where everybody is allowed to give a talk. Usually, there’s a big notepad with the schedule in front of the room where you can write down your name and subject of the talk. If you want to learn how to give a talk in public an uncon session is the perfect playground.

Be sure to socialize a bit with your fellow artisans between the talks. It’s incredible how much you can learn from everybody.

And last but not least: just have fun!

Source: Laravel News

Welcome to the next version of Laravel News

Four years ago Laravel News got its start as a simple Twitter and Facebook account where I would share things created by the Laravel community and try to help out the creators as well as users find new awesome stuff. From there it transitioned into a Tumblr site and finally into a full website that’s been running for the past three years.

Back in May Laravel announced that Laravel News would be the official Laravel blog and I didn’t like how my current design looked amateurish compared to the rest of the Laravel sites. To remedy that I partnered up with Zaengle who helped take my ideas and turn it into something that I am extremely happy with and proud to bring to the community.

During this move, I have redone the way the site is powered. Previously it ran on WordPress with a custom theme I put together, it worked fine but added new features, and sections became harder and harder, and I wanted the ability to use what I am comfortable with, Laravel. However, I didn’t want to give up the media library and editing experience of WordPress.

So to have the best of both worlds I kept the old site on WordPress and used the WP Rest API paired with the Laravel Scheduler. This allows me to automatically sync data from WordPress into my database without having to rebuild an entire CMS admin area. I have the same setup for the podcast section, and it hooks into the Simplecast API to pull those over.

I’m sure you think this is crazy and it might be but if you are interested in how it all works let me know and I’ll write up a tutorial. I’m pretty confident only a site ran by a developer would like this setup.

While I was working on all this, I didn’t have time to finish all the sections of the new site. You may notice the community links are missing, and the search is hit or miss. I decided to roll out without these features and will be adding links back soon and better searching once 5.3 is released with Laravel Scout.

I hope you like the new site as much as I do, and I want to thank you all.

P.S. If you spot any errors or problems I setup a new bugs repo where you can submit it.

Source: Laravel News

Turbolinks with Laravel

Today, I’m tinkering around with Turbolinks, which was recently – at the time of this writing – extracted to its own library that may be used anywhere. It’s pretty sweet! Drop it in, and it instantly begins working. All anchor links clicks will be intercepted, and AJAX requests will be sent in their place. This allows for a signifiant performance boost, as the user only needs to download relevant scripts and stylesheets once on the initial page load.
Source: Laracasts

Hide Your Secret Passwords

At the moment, we’re hardcoding our database username and password directly within the Connection class. But, we don’t really want to do this. It’s too dangerous. Instead, let’s extract any secret passwords or keys for our app into its own file, and then lock that down.
Source: Laracasts

1 12 13 14 15 16 53