How do display iframe inside laravel blade

Viewed 12597

I've been working on a project with pure vanilla html and php and I want to transfer it to laravel. Now I'm stuck when I want to show an iframe (a blade file) inside another page (another blade file). The parent page is displaying but the iframe is bringing 404 (not found) error. Below is my code:

Note that these two files are in the same folder in the "view" directory.

parent.blade.php

<iframe src="child.blade.php">Your browser isn't compatible</iframe>

route

Route::group(['prefix' => 'parent'], function () {
    Route::get('/', 'ParentController@index');
    Route::get('/child', 'ParentController@child');
});

controllers

public function index()
{
   return view('folder/index');
}

public function child()
{
   return view('folder/child');
}
2 Answers

It should be the URL of the route not the view path:

//parent.blade.php

<iframe src="{{url('parent/child')}}">Your browser isn't compatible</iframe>

Change the src from child.blade.php to {{ url('parent/child') }}. You named a blade file, not a URL like you're used to.

Or even more the Laravel way: name your routes for even easier routing:

Routes:

Route::group(['prefix' => 'parent'], function () {
    Route::get('/', 'ParentController@index');
    Route::get('/child', 'ParentController@child')->name('child');
});

Blade:

<iframe src="{{ route('child') }}">Your browser isn't compatible</iframe>
Related