PHP code example of aidynmakhataev / laravel-attributes

1. Go to this page and download the library: Download aidynmakhataev/laravel-attributes 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/ */

    

aidynmakhataev / laravel-attributes example snippets


return [
    'events' => [
        /*
         * Automatic registration of listeners will only happen if this setting is `true`
         */
        'enabled'       => true,

        /*
         * Listeners in these directories that have attributes will automatically be registered.
         */
        'directories'   => [
            base_path('app/Listeners')
        ]
    ],

    'command_bus' => [
        /*
         * Automatic registration of command handlers will only happen if this setting is `true`
         */
        'enabled'       => true,

        /*
         * Handlers in these directories that have attributes will automatically be registered.
         */
        'directories'   => [
            base_path('app/CommandHandlers')
        ],
    ],

    'routing' => [
        /*
         * Automatic registration of routes will only happen if this setting is `true`
         */
        'enabled'       => true,

        /*
         * Controllers in these directories that have attributes will automatically be registered.
         */
        'directories'   => [
            base_path('app/Http/Controllers')
        ],
    ],
];


namespace App\Listeners;

use AidynMakhataev\LaravelAttributes\Attributes\EventListener;
use App\Events\OrderShipped;

class SendShipmentNotification
{
    #[EventListener]
    public function handle(OrderShipped $event)
    {
        //
    }
}

Event::listen(OrderShipped::class, 'SendShipmentNotification@handle');


namespace App\CommandHandlers;

use AidynMakhataev\LaravelAttributes\Attributes\CommandHandler;
use App\Events\OrderShipped;

class CreateOrderCommandHandler
{
    #[CommandHandler]
    public function handle(CreateOrderCommand $command)
    {
        //
    }
}

Bus::map([
    CreateOrderCommand::class => CreateOrderCommandHandler::class,
]);


namespace App\Http\Controllers;

use AidynMakhataev\LaravelAttributes\Attributes\Route;
use App\Events\OrderShipped;
use Illuminate\Http\Request;

class OrderController
{
    #[Route(path: '/orders', methods: ['POST'], name: 'orders.store', middlewares: ['auth'])]
    public function store(Request $request)
    {
        //
    }
}

Route::post('/orders', [OrderController::class, 'store'])->name('orders.store')->middlewares(['auth']);
bash
php artisan vendor:publish --provider="AidynMakhataev\LaravelAttributes\LaravelAttributesServiceProvider" --tag="config"