Skip to content

Releases: lorisleiva/laravel-actions

v1.0.0

08 May 15:31
e72337b
Compare
Choose a tag to compare

What's new?

⚡️ Run actions as commands (documentation)

You can now run actions as commands by simply providing the commandSignature static property.

class PublishANewArticle extends Action
{
    protected static $commandSignature = 'make:article {title} {body}';
    protected static $commandDescription = 'Publishes a new article';

    // ...
}

🚗 Register routes directly in actions (documentation)

You can now register your routes directly in the routes static method of your actions.

class GetArticlesFromAuthor extends Action
{
    public static function routes(Router $router)
    {
        $router->get('author/{author}/articles', static::class);
    }

    public function handle(User $author)
    {
        return $author->articles;
    }
}

🧙‍♂️ instantiate an action with custom arguments (documentation)

Imagine the following GetItineraryInstructions action that returns an array of strings given an address and a transportation mode. Here is how you would need to instantiate this action:

$action = new GetItineraryInstructions([
    'address' => $address,
    'mode' => 'driving',
]);

However, in this particular case, this action will always take an address and a mode attribute so wouldn't it be better if we could just write this instead?

$action = new GetItineraryInstructions($address, 'driving');

Well, starting from v1.0, you can. All you need to do to make this work is to define your custom logic in the getAttributesFromConstructor method. See the documentation to learn more about this.

Note that, this will also work with the run and dispatch static methods.

// As an object.
GetItineraryInstructions::run($address, 'driving');

// As a job.
GetItineraryInstructions::dispatch($address, 'driving');

How to upgrade from 0.x?

📦 Composer update

# In your composer.json
"lorisleiva/laravel-actions": "^1.0",
composer update lorisleiva/laravel-actions

🚨 Potential breaking changes

  • The register method has been renamed initialized. It will be called every single time an action is instantiated no matter how it is running. (See The lifecycle of an action).

  • In order to register actions as commands and register routes directly within actions, Laravel Actions need to know where your Actions are kept. By default, it will look inside the app/Actions directory. This new discovery mechanism might interfere with your current architecture. If this is the case, you can tell Laravel Actions were to look for actions using Actions::paths([...]) in a service provider. Alternatively you can disable this altogether via the Actions::dontRegister() method. (See Registering actions).

  • Finally, A few internal method signatures have been adjusted.

    - public function updateAttributeWithResolvedInstance($key, $instance)
    + protected function updateAttributeWithResolvedInstance($key, $instance): void
    
    - protected function findAttributeFromParameter($name, $extras = [])
    + protected function findAttributeFromParameter($name, $extras = []): array
    
    - protected function resolveMethodDependencies($instance, $method, $extras = [])
    + protected function resolveMethodDependencies($instance, $method, $extras = []): array
    
    - public function delegateTo($actionClass)
    + public function delegateTo(string $actionClass)

v0.3.0

01 Mar 13:18
1cf1b60
Compare
Choose a tag to compare

⬆️ Add support for Laravel 7 (#35)
🐎 No longer instantiate every listener to check if it's an action (#33)
✨ Add the following new static helpers to run actions (#36)

MyAction::make([/* ... */])

// Equivalent to:
new MyAction([/* ... */]);
MyAction::run([/* ... */])

// Equivalent to:
(new MyAction)->run([/* ... */]);

⚠️ This is a potential breaking change if your application is overriding the run method. If that's the case make sure to override the handleRun method instead.

// Previous signature to override.
public function run(array $attributes = [])

// New signature to override.
protected function handleRun(array $attributes = [])

v0.2.5

02 Jan 19:12
Compare
Choose a tag to compare

Add support for dependency injection to the following methods: rules(), messages() and attributes().

This means you can now resolve your Eloquent models or Service classes before even reaching the handle() method.

This could be helpful, for example, when excluding a model in a unique rule.

class UpdateTeamProfile extends Action
{
    public function rules(Team $team)
    {
        return [
            'name' => ['filled', 'max:255'],
            'slug' => [
                'filled',
                'alpha_dash',
                Rule::exists('teams')->ignore($team->id),
            ],
        ];
    }
    
    public function handle(Team $team)
    {
        $team->update($this->validated());

        return $team;
    }
}

v0.2.4

16 Nov 11:17
Compare
Choose a tag to compare

🐛 Edit the Bus Dispatcher so that it uses the action itself as a job handler instead of a proxy. This allows the use of properties like public $timeout directly within the action. (see #28)

v0.2.3

31 Oct 09:30
Compare
Choose a tag to compare
  • 📝 Define __isset magic method. (#27)
  • 🐛 Restart validation every time we re-run an action. (#26)

v0.2.2

21 Oct 09:35
96f4bbf
Compare
Choose a tag to compare
  • Clear cached Event Facade instance (46028c2)
  • Add prepareForValidation method (9c99635)

v0.2.1

03 Sep 14:36
Compare
Choose a tag to compare

⬆️ Add support for Laravel 6.x

v0.2.0

05 Aug 16:48
Compare
Choose a tag to compare

⚠️ Middleware registration (breaking changes) In preparation of Laravel 6, the middleware registration changes slightly to follow the same API as the upcoming Job middleware.

// Before.
public function register()
{
    $this->middleware('auth');
}

// After.
public function middleware()
{
    return ['auth'];
}

Actions are now invokable as objects

// When running an action as an object.
$action = new PublishANewArticle([
    'title' => 'My blog post',
    'body' => 'Lorem ipsum.',
]);

// You can now run it like this...
$action();

// Which is equivalent to...
$action->run();

v0.1.4

30 Jul 09:17
ad70300
Compare
Choose a tag to compare

🚑 Fix namespace typo (#16)

v0.1.3

10 Jun 06:55
e9835f6
Compare
Choose a tag to compare

🚑 Fix issue #7 by decorating the existing event dispatcher instead of overriding it with a new instance.