laravel-5-helper
FormatResponce, (*1)
To return json or html on same route.
Register Middleware, add this to app/Http/Kernel.php in middlewareGroups array in web, as last one of them:, (*2)
iWedmak\Helper\Middleware\FormatResponce::class,
now you can return array from your controllers this way:, (*3)
return ['data'=>$data, 'view'=>'someview'];
check looks like that:, (*4)
$response = $next($request);
try
{
if (method_exists($response, 'getOriginalContent'))
{
$data = $response->getOriginalContent();
if(isset($data['data']) && !empty($data['data']))
{
if ($request->wantsJson())
{
$response=response()->json($data['data']);
$response->header('Content-Length',mb_strlen($response->getContent()));
}
else
{
$response=response()->view($data['view'], $data['data']);
}
}
}
}
catch(BadMethodCallException $e)
{
}
return $response;
xCache, (*5)
Register provider, add this to config/app.php in providers array:, (*6)
iWedmak\Helper\Providers\CacheServiceProvider::class,
Register xcache driver, add this to config/cache.php in stores array:, (*7)
'xcache' => [
'driver' => 'xcache',
],