Laravel 5.3 is a feature-packed release introducing the notification system, Echo for real-time, and Scout for search. These additions make building modern applications significantly easier. At ZIRA Software, we've adopted all these features across our projects.
Notification System
// Create notification
php artisan make:notification OrderShipped
// app/Notifications/OrderShipped.php
class OrderShipped extends Notification
{
use Queueable;
protected $order;
public function __construct(Order $order)
{
$this->order = $order;
}
public function via($notifiable)
{
return ['mail', 'database', 'broadcast'];
}
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Order Shipped!')
->line('Your order #' . $this->order->id . ' has shipped.')
->action('Track Order', url('/orders/' . $this->order->id))
->line('Thank you for shopping with us!');
}
public function toDatabase($notifiable)
{
return [
'order_id' => $this->order->id,
'message' => 'Your order has shipped!',
];
}
public function toBroadcast($notifiable)
{
return new BroadcastMessage([
'order_id' => $this->order->id,
'message' => 'Your order has shipped!',
]);
}
}
// Send notification
$user->notify(new OrderShipped($order));
// Or via facade
Notification::send($users, new OrderShipped($order));
Laravel Echo (Real-time)
// Install Echo
npm install laravel-echo pusher-js
// bootstrap.js
import Echo from 'laravel-echo';
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: process.env.MIX_PUSHER_APP_KEY,
cluster: process.env.MIX_PUSHER_APP_CLUSTER,
});
// Listen for notifications
Echo.private(`App.User.${userId}`)
.notification((notification) => {
console.log(notification.message);
});
// Listen to channel events
Echo.channel('orders')
.listen('OrderCreated', (e) => {
console.log('New order:', e.order);
});
// Presence channels
Echo.join(`chat.${roomId}`)
.here((users) => {
// Current users in channel
})
.joining((user) => {
console.log(user.name + ' joined');
})
.leaving((user) => {
console.log(user.name + ' left');
});
Laravel Scout (Search)
composer require laravel/scout
composer require algolia/algoliasearch-client-php
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
// Add Searchable trait to model
use Laravel\Scout\Searchable;
class Post extends Model
{
use Searchable;
public function toSearchableArray()
{
return [
'id' => $this->id,
'title' => $this->title,
'content' => $this->content,
'author' => $this->author->name,
'tags' => $this->tags->pluck('name'),
];
}
public function searchableAs()
{
return 'posts_index';
}
}
// Search
$posts = Post::search('laravel tutorial')->get();
// With filters
$posts = Post::search('laravel')
->where('published', true)
->paginate(15);
// Import existing records
php artisan scout:import "App\Post"
Mailable Classes
// Create mailable
php artisan make:mail WelcomeEmail
// app/Mail/WelcomeEmail.php
class WelcomeEmail extends Mailable
{
use Queueable, SerializesModels;
public $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function build()
{
return $this->subject('Welcome to Our Platform!')
->view('emails.welcome')
->with(['loginUrl' => url('/login')]);
}
}
// Send
Mail::to($user)->send(new WelcomeEmail($user));
// Queue
Mail::to($user)->queue(new WelcomeEmail($user));
Directory Structure Changes
Laravel 5.3 Directory
├── app/
│ ├── Notifications/ ← New
│ ├── Mail/ ← New
│ └── ...
├── routes/
│ ├── web.php ← Renamed from app/Http/routes.php
│ ├── api.php ← New
│ ├── console.php ← New
│ └── channels.php ← New for broadcast auth
Conclusion
Laravel 5.3 brings enterprise features to every Laravel app. Notifications, Echo, and Scout enable rich user experiences with minimal code. These tools have become essential for modern Laravel development.
Upgrading to Laravel 5.3? Contact ZIRA Software for migration assistance.