承接 victor-falcon/laravel-task 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

victor-falcon/laravel-task

Composer 安装命令:

composer require victor-falcon/laravel-task

包简介

A simple laravel task trigger

关键字:

README 文档

README

Laravel Task

GitHub Workflow Status Packagist Packagist Packagist

🇪🇸 Documentación en español aqui

Table of content:

Installation

Install via composer

# PHP >= 8
composer require victor-falcon/laravel-task
# Previous PHP versions
composer require victor-falcon/laravel-task:1.1.4

Usage

1. Basic usage

Create a simple task using:

artisan task:make Shop/CreateUserShop

You can pass Shop/CreateUserShop to create the class in a sub-folder or just the task name. The default path is app/Tasks.

<?php

declare(strict_types=1);

namespace App\Tasks\Shop;

use VictorFalcon\LaravelTask\Task;
use VictorFalcon\LaravelTask\Taskable;

final class CreateUserShop implements Task
{
	use Taskable;

	private User $user;

	public function __construct(User $user)
	{
		$this->user = $user;
	}

	public function handle(ShopCreator $creator): Shop
	{
		// Create your shop
	}
}

and trigger it:

$shop = CreateUserShop::trigger($user);

2. With validation

If you want, you can pass validated data to your tasks using the Laravel validator. For example, If you need to validate a user creation you can do something like this.

final class CreateUser implements Task
{
	public function rules(): array
	{
		return [
			'name' => 'required|string|min:5',
			'email' => 'required|email|unique:users,email',
		];
	}

	public function handle(): User
	{
		return User::create($this->data);
	}
}

And then you can trigger your task with extra data using:

CreateUser::trigger()->withValid([
	'name' => 'Víctor Falcón',
	'email' => 'hi@victorfalcon.es',
]);

You can customize the messages with the method messages(): array in your task or add custom attributes with customAttributes(): array.

If you want to customize the errors bag name of the validator just define the string $errorBag property in your class.

3. With authorization

Sometimes you need to check if the user triggering the task is authorized or not. You can do that by adding a simple authorize(): bool method to your task. If this method returns false an AuthorizationException will thrown on before execution.

public function authorize(): bool
{
	return $this->user()->can('create', Product::class);
}

In any task you can access to the current logged user with $this->user() or, if you want, you can pass a user object by doing:

CreateProduct::trigger()->by($user);

4. Recover response

By default, each task is executed without returning any value. So if you want to recover the result of a task you must call the result() method.

// This will return the result of the `handle` method inside our task
$product = CreateProduct::trigger()->withValid($data)->result();

Generate IDE Help

In order to make more easy to write and use your task you can generate a _ide_helper_tasks.php file automatically with the artisan task:ide-help command.

Update config

If you want, you can publish the package config to customize, for example, where do you want you task to be store at:

artisan vendor:publish --tag=laravel-task

Credits

victor-falcon/laravel-task 适用场景与选型建议

victor-falcon/laravel-task 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 272 次下载、GitHub Stars 达 17, 最近一次更新时间为 2020 年 11 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「task」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 victor-falcon/laravel-task 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 victor-falcon/laravel-task 我们能提供哪些服务?
定制开发 / 二次开发

基于 victor-falcon/laravel-task 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 272
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-12