29 lines
1.1 KiB
Markdown
29 lines
1.1 KiB
Markdown
---
|
|
title: >
|
|
Laravel Pipelines
|
|
pubDate: 2023-04-23
|
|
permalink: >-
|
|
daily/2023/04/23/laravel-pipelines
|
|
tags:
|
|
- php
|
|
- laravel
|
|
---
|
|
|
|
I've seen a lot on social media and posts and videos recently about Laravel Pipelines - functionality that's been present in Laravel and used within the framework for some time - but there was only documentation added for it last month as part of the Laravel 10 release.
|
|
|
|
This is an example from the new documentation:
|
|
|
|
```language-php
|
|
$user = Pipeline::send($user)
|
|
->through([
|
|
GenerateProfilePhoto::class,
|
|
ActivateSubscription::class,
|
|
SendWelcomeEmail::class,
|
|
])
|
|
->then(fn (User $user) => $user);
|
|
```
|
|
|
|
Once a user has registered, it is passed through different classes - each performing a task and calling the next class in the list, similar to middleware. Once finished, a final action is performed or a value is returned.
|
|
|
|
As someone who doesn't use Laravel often but does use standalone components - like `illuminate/collections` - in other PHP projects, I'm interested to see how I can use this via `illuminate/pipeline` to refactor some of my existing code.
|