PHP code example of victor-falcon / laravel-task

1. Go to this page and download the library: Download victor-falcon/laravel-task library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

victor-falcon / laravel-task example snippets




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
	}
}

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

final class CreateUser implements Task
{
	public function rules(): array
	{
		return [
			'name' => 'urn User::create($this->data);
	}
}

CreateUser::trigger()->withValid([
	'name' => 'Víctor Falcón',
	'email' => '[email protected]',
]);

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

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

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