Skip to content

Instantly share code, notes, and snippets.

@sebastiaanluca
Last active August 14, 2017 17:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastiaanluca/4b3ac6aee3c8a0d832959b6e03a5e0c2 to your computer and use it in GitHub Desktop.
Save sebastiaanluca/4b3ac6aee3c8a0d832959b6e03a5e0c2 to your computer and use it in GitHub Desktop.
Laravel 5.5 request handling
<?php
namespace App\Http;
use SebastiaanLuca\Flow\Http\RequestHandler as BaseRequestHandler;
use SebastiaanLuca\Flow\Http\ShowsViews;
class RequestHandler extends BaseRequestHandler
{
use ShowsViews;
}
<?php
namespace SebastiaanLuca\Flow\Http;
class RequestHandler
{
/**
* Executed when the object itself is called as a method.
*
* Pass the call on to a handle method for improved readability.
*
* @return mixed
*/
public function __invoke()
{
return call_user_func_array([$this, 'handle'], func_get_args());
}
}
<?php
namespace SebastiaanLuca\Flow\Http;
use Illuminate\Contracts\View\View;
trait ShowsViews
{
/**
* @var array
*/
protected $viewData = [];
/**
* @param string $path
* @param array $data
*
* @return \Illuminate\Contracts\View\View
*/
protected function view(string $path, array $data = []) : View
{
return view($path, $this->viewData, $data);
}
/**
* @param array|string $key
* @param mixed $value
*
* @return $this
*/
protected function addViewData($key, $value = null)
{
$data = $key;
if (! is_array($key)) {
$data = [$key => $value];
}
$this->viewData = array_merge($this->viewData, $data);
return $this;
}
}
<?php
namespace Core\Http\RequestHandlers;
use App\Http\RequestHandler;
use Illuminate\Contracts\View\View;
class ShowHomepage extends RequestHandler
{
/**
* @return \Illuminate\Contracts\View\View
*/
public function handle() : View
{
return $this->view('core::pages.homepage');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment