Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sahil1711's avatar

Can't use iframes to embed the widget at other places.

So in my laravel app, I had to create a screen as an iframe , so that it can be embeddable in notion. So i create an page with iframe in my app , but that link is not embeddable anywhere else. Here's my wip: https://kanbancast.com/api/embed/arwn30IP3lx3

0 likes
4 replies
LaryAI's avatar
Level 58

To make your Laravel app's page embeddable in an iframe, you need to ensure that the appropriate HTTP headers are set to allow embedding. By default, many web applications include headers that prevent embedding to protect against clickjacking attacks.

In Laravel, you can control these headers using middleware. Here's a step-by-step solution:

  1. Create Middleware to Allow Embedding:

    First, create a new middleware that will set the necessary headers to allow embedding.

    php artisan make:middleware AllowIframe
    
  2. Modify the Middleware:

    Open the newly created middleware file located at app/Http/Middleware/AllowIframe.php and modify it to set the X-Frame-Options header to ALLOWALL.

    <?php
    
    namespace App\Http\Middleware;
    
    use Closure;
    use Illuminate\Http\Request;
    
    class AllowIframe
    {
        /**
         * Handle an incoming request.
         *
         * @param  \Illuminate\Http\Request  $request
         * @param  \Closure  $next
         * @return mixed
         */
        public function handle(Request $request, Closure $next)
        {
            $response = $next($request);
            $response->headers->set('X-Frame-Options', 'ALLOWALL');
            return $response;
        }
    }
    
  3. Register the Middleware:

    Next, register the middleware in your app/Http/Kernel.php file. You can add it to the $routeMiddleware array if you want to apply it to specific routes, or to the $middleware array if you want it to apply globally.

    protected $routeMiddleware = [
        // Other middleware
        'allowiframe' => \App\Http\Middleware\AllowIframe::class,
    ];
    
  4. Apply the Middleware to Your Route:

    Finally, apply the middleware to the route that serves the page you want to embed. For example, if your route is defined in routes/web.php:

    Route::get('/api/embed/{id}', [YourController::class, 'yourMethod'])->middleware('allowiframe');
    
  5. Verify the Headers:

    Ensure that the headers are correctly set by checking the response headers in your browser's developer tools. You should see the X-Frame-Options header set to ALLOWALL.

By following these steps, you should be able to embed your Laravel app's page in an iframe on other sites, including Notion.

sahil1711's avatar

So i also saw something about changing config/sessions with same-site none thing. But that doesn't work right now for me as well.

Please or to participate in this conversation.