Skip to content

Instantly share code, notes, and snippets.

@JayBizzle
Created January 24, 2017 16:25
Show Gist options
  • Save JayBizzle/73f8c09ee5cf2444e06fbac40710fd7b to your computer and use it in GitHub Desktop.
Save JayBizzle/73f8c09ee5cf2444e06fbac40710fd7b to your computer and use it in GitHub Desktop.
boot() method
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
/**
* Override method to allow us to call a boot method
* before running requested route method.
*
* @param string $method
* @param array $parameters
* @return \Symfony\Component\HttpFoundation\Response
*/
public function callAction($method, $parameters)
{
if (method_exists($this, 'boot')) {
$this->boot();
}
return parent::callAction($method, $parameters);
}
}
<?php
class HomeController extends BaseController
{
/**
* Create a new HubController instance.
*
* @return void
*/
public function __construct()
{
// Some contructor stuff
}
/**
* Boot method runs after middleware and before route action.
*
* @return void
*/
public function boot()
{
view()->share('user', auth()->user());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment