如何在 laravel 中 return 非 blade 视图?

How to return non blade based view in laravel?

我有带有 HTML 和 PHP 代码的自定义 php 文件(index.php 而不是 index.blade.php)。如何将此文件用作 laravel 和 return 中的视图?

我这样试过但没有用:

Return view("index.php");

Laravel public / index.php 中已有 index.php 个文件 尝试将其重命名为其他名称并尝试。

I have custom php file (index.php and not index.blade.php) with HTML & PHP codes. How I can use this file as view in laravel and return it?

我强烈建议使用 Laravel's Blade Engine and stick to the MVC 将视图与业务逻辑分开的原则。

但是,如果您必须改用自定义 PHP 文件,那么您可以这样做:

class YourController extends Controller
{    
   public function index() 
   {
      $content = require 'path/to/your/index.php'; 
      return $content;
   }   

}

如果您的路径指向资源目录,您可以使用 resource_path 助手:

$content = require resource_path('views/index.php');