iwedmak/helper

Some personal helpfull functons

0.0.5 2019-09-08 07:53 UTC

This package is auto-updated.

Last update: 2024-12-08 19:16:14 UTC


README

FormatResponce

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:

iWedmak\Helper\Middleware\FormatResponce::class,

now you can return array from your controllers this way:

return ['data'=>$data, 'view'=>'someview'];

check looks like that:

$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

Register provider, add this to config/app.php in providers array:

iWedmak\Helper\Providers\CacheServiceProvider::class,

Register xcache driver, add this to config/cache.php in stores array:

'xcache' => [
    'driver' => 'xcache',
],