Created
January 24, 2017 16:25
-
-
Save JayBizzle/73f8c09ee5cf2444e06fbac40710fd7b to your computer and use it in GitHub Desktop.
boot() method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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