function yp_body($content) { $turbo = new Turbo(); if ($turbo->isPjax()) { return $turbo->extract((string) $content); } }
/** * Get the content/body to return to browser. * * If the request is a pjax one, only the body is returned. * * @param string $value * @return string */ public function body($value = false) { $value and $this->body = $value; // Deal with pjax request $turbo = new Turbo(); if ($turbo->isPjax()) { $this->body = $turbo->extract((string) $this->body); } // Fire event, then remove so that not called multiple times Event::trigger('turbo.pjax'); Event::unregister('turbo.pjax'); return parent::body($this->body); }
/** * Register the service provider. * * @return void */ public function register() { App::after(function ($request, $response) { $turbo = new Turbo(); if ($turbo->isPjax()) { if (is_a($response, 'Illuminate\\Http\\Response')) { // Extract the body from the response $content = (string) $response->getOriginalContent(); $body = $turbo->extract($content); // Set new response content $response->setContent($body); } // Fire that we are in a pjax request Event::fire('turbo.pjax', array($request, $response)); } }); }