PHP code example of onramplab / laravel-clean-architecture

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

    

onramplab / laravel-clean-architecture example snippets


namespace App\UseCases;

use OnrampLab\CleanArchitecture\UseCase;
use Spatie\LaravelData\Attributes\Validation\Url;

class DoSomethingUseCase extends UseCase
{
    #[Url()]
    public string $url;

    public function handle(): string
    {
        return 'do something';
    }
}

use App\Http\Controllers\Controller;
use App\UseCases\DoSomethingUseCase;
use Illuminate\Http\Request;

class DoSomethingController extends Controller
{
    public function doSomething(Request $request)
    {
        $result = DoSomethingUseCase::perform([
            'url' => $request->input('url'),
        ]);

        return response()->json([
            'result' => $result,
        ]);
    }
}


namespace App\Exceptions;

use OnrampLab\LaravelExceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
   // ...
}