iWedmak / laravel-5-helper by iWedmak

Some personal helpfull functons
197
0
1
Package Data
Maintainer Username: iWedmak
Maintainer Contact: iwedmak@gmail.com (iWedmak Om)
Package Create Date: 2016-03-31
Package Last Update: 2019-09-08
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:04:42
Package Statistics
Total Downloads: 197
Monthly Downloads: 2
Daily Downloads: 1
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 1

laravel-5-helper

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',
],