Sefa Dönmezcan
Sefa Dönmezcan

Reputation: 27

Laravel 8 view()->nest usage

our project coming from laravel 3.x, we'r upgrading to laravel 8 but we have a problem on nest, error says undefined function 'nest'.

return view('pages.' . Str::lower($this->table) . 'list', $data)
  ->nest('filterbar', 'sections.filterbar', $data)
  ->nest('commandbar', 'sections.commandbar', $data);

Upvotes: 0

Views: 417

Answers (1)

Adnane Kadri
Adnane Kadri

Reputation: 67

Sometimes you may wish to pass a view into another view. For example, given a sub-view stored at app/views/child/view.php . in old versions of laravel , we could pass it to another view like so:

$view = View::make('greeting')->nest('child', 'child.view', $data);

The sub-view can then be rendered from the parent view:

<html>
    <body>
        <h1>Hello!</h1>
        <?php echo $child; ?>
    </body>
</html>

and here where is the nest function is available . but in newest versions of laravel , you can just include that child view in the parent view in order to use it .. using the blade directive @include can be really helpful at that point .

so instead of :

return view('pages.' . Str::lower($this->table) . 'list', $data)
  ->nest('filterbar', 'sections.filterbar', $data)
  ->nest('commandbar', 'sections.commandbar', $data);

you can just return the parent view :

return view('pages.' . Str::lower($this->table) . 'list', compact('data'); 

and somewhere inside these views , instead of using the subview , you would need to include it :

@include('sections.commandbar')

Upvotes: 1

Related Questions