1. Go to this page and download the library: Download patienceman/custom-handler 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/ */
patienceman / custom-handler example snippets
App\Handlers
namespace App\Handlers;
use Patienceman\CustomHandler\Handler;
class NewStartupHandler extends Handler {
/**
* Custom execution from Handler Pipeline
* @return Exception|void
*/
public function execute() {
// do whatever action inside handler
}
}
namespace App\Http\Controllers;
use App\Handlers\NewStartupHandler;
use Patienceman\CustomHandler\CustomHandler;
class TestBuilderController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$handler = CustomHandler::handle(new NewStartupHandler());
}
}
namespace App\Http\Controllers;
use App\Handlers\NewStartupHandler;
use App\Handlers\NewCompanyHandler;
use Patienceman\CustomHandler\CustomHandler;
class TestBuilderController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$handler = CustomHandler::handle(new NewStartupHandler())
->handle(new NewCompanyHandler());
}
}
namespace App\Handlers;
use Patienceman\CustomHandler\Handler;
use App\Models\Startup;
class NewStartupHandler extends Handler {
/**
* Custom execution from Handler Pipeline
* @return Exception|void
*/
public function execute() {
$startup = Startup::create([ 'name' => "MorganTv" ]);
$this->collect([ 'startup' => $startup ]);
}
}
namespace App\Handlers;
use Patienceman\CustomHandler\Handler;
class NewCompanyHandler extends Handler {
/**
* Custom execution from Handler Pipeline
*
* @return Exception|void
*/
public function execute() {
$startup = $this->collection()->get('startup');
}
}
namespace App\Http\Controllers;
use App\Handlers\NewStartupHandler;
use App\Handlers\NewCompanyHandler;
use Patienceman\CustomHandler\CustomHandler;
class TestBuilderController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$handler = CustomHandler::handle(new NewStartupHandler())
->handle(new NewCompanyHandler())
->collection()
->get('startup') // or ->get(), ->filter() ->sort();
}
}