Specify a different layout file

What seems to be the problem: Each time I try to specify a different layout file for a full-page component I get the the error “Method Illuminate\View\View::layout does not exist.” or “Method Illuminate\View\View::extends does not exist.”

Steps to Reproduce: In controller component:
[ public function render()
{
return view(‘livewire.enrol.apply’)
->layout(‘layouts.applym’);
}
]

Route: [
Route::livewire(’/apply’, ‘enrol.apply’)->name(‘apply’);
]
I want the component enrol.apply to use the layouts.applym.blade.php.

Are you using the latest version of Livewire: Yes

Do you have any screenshots or code examples: Yes

If you are using LW V2, The Livewire method was removed
and you can try to use a different implementation of extending layouts

You can See More here

// Before
Route::livewire('/post', ShowPosts::class)
    ->layout('layouts.base')
    ->section('body');

// After
class ShowPosts extends Component
{
    public function render()
    {
        return view('livewire.show-posts')
            ->extends('layouts.base')
            ->section('body');
    }
}
// Before
Route::livewire('/post', 'show-posts');

// After
Route::get('/post', \App\Http\Livewire\ShowPosts::class);

Great!! I had missed that. Thank you very much.

You are very welcome :wink:

Take a look at this issue https://stackoverflow.com/q/64642147/4650866

Won’t work in laravel 8

Just add a backslash \ at the end of the namespace.

Only This

Route::get('/create', [CreateDomain::class, '__invoke'])->name('create');

Works For Me

You can do it either ways. With use namespace at the top of your file or injecting the full namespace.