Slide 71
Slide 71 text
View Data Composition: View Components
class NavigationComponent implements Htmlable
{
public function __construct(Request $request, $backgroundColor)
{
$this->request = $request;
$this->backgroundColor = $backgroundColor;
}
public function toHtml()
{
return view('components.navigation', [
'activeUrl' => $this->request->url(),
'backgroundColor' => $this->backgroundColor,
]);
}
// In use:
@render('navigationComponent', ['backgroundColor' => 'black'])