Notifications: Database

Let’s move on and review the database channel for sending notifications. With this approach, any notification you send will be stored in the database, at which point you can fetch them and display them for the user. In this episode, we’ll review the entire process – while also leveraging polymorphism to render each notification type within our views as cleanly as possible.
Source: Laracasts

Laravel Mailable: The new and improved way to send email in Laravel

A new feature in Laravel 5.3 is a way to simplify sending email by creating “mailable” classes that handle setting up your emails.

The best way to explain this feature is with an example. In Laravel 5.2 you would typically send an email like the following that is outlined in the documentation:

Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
    $m->from('hello@app.com', 'Your Application');
    $m->to($user->email, $user->name)->subject('Your Reminder!');
}); 

A lot is going on in those four lines of code. You pass a view, data to assign to the view, use the “user” in the closure, and finally setup your message.

Now in Laravel 5.3 you can simplify this by utilizing a “mailable” class.

php artisan make:mail YourReminder

Next, open the new class that is created and all of a mailable configuration is done in the build method. Within this, you may call various methods such as from, subject, view, and attach to configure the email’s presentation and delivery. Here is a minimal example:

public function build()
{
    return $this->from('example@example.com')
        ->view('emails.reminder');
}

Now, anytime you want to send this email you can call it like this:

Mail::to($email)->send(new YourReminder);

All of the existing mail features still work. You can queue, add cc, bcc, attach files and more.

If you’d like to learn more about Laravel Mailable here are a few resources to help you on your journey:

Source: Laravel News

Laracon EU is almost sold out.

Laracon EU is almost sold out and this is your last chance to get tickets and attend the conference. The conference is going to be August 23rd and 24th which is only about two weeks away.

If you purchase in the next three days you can lock in the €399 ticket price, if not then last-minute pricing goes into effect which is €499 and there is no guarantee those are even going to be available.

This is your last chance to attend this year’s Laracon EU and if you are on the fence you should act fast before it’s to late.

Source: Laravel News

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

1 12 13 14 15 16 54