douke7274
2018-03-13 16:46
浏览 307
已采纳

require_once()在Laravel代客托管的项目中打开资源失败

I am just picking up using Laravel, but I dont like Vue and have been working with the React ecosystem and would like to use React instead of Vue. Laravel Mix doesnt give me the setup I want and so I figured I could use create-react-app.
Using Laravel Valet, I have started a project in which I have also installed create-react-app in a folder called ui, at the root of the Laravel installation.

My idea is to forego some of Laravel's functionality, namely the whole frontend.

I am attempting to require the react app build html file in resources/views/main.blade.php like so: require_once __DIR__.'/ui/build/index.html';

This gives me the error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Illuminate\View\Engines\PhpEngine::main(): Failed opening required '/Users/Username/Sites/sitename/storage/framework/views/ui/build/index.html' (include_path='.:')

This path is not correct, but I'm not sure why it is inserting /storage/framework/ into that path.

I have also tried the following, each with a similar error of Failed opening resource:

require_once('../../ui/build/index.html'); require_once($_SERVER['DOCUMENT_ROOT'].'/ui/build/index.html'); require_once(dirname(__FILE__).'/ui/build/index.html');

图片转代码服务由CSDN问答提供 功能建议

我刚刚使用Laravel,但我不喜欢Vue并且一直在使用React生态系统,并希望 使用React而不是Vue。 Laravel Mix没有给我我想要的设置,所以我想我可以使用create-react-app。
使用Laravel Valet,我已经启动了一个项目,我在其中也安装了create-react-app ui,在Laravel装置的根部。

我的想法是放弃一些Laravel的功能,即整个前端。

我正在尝试 要求react app在 resources / views / main.blade.php 中构建html文件,如下所示: require_once __DIR __。'/ ui / build / index.html';

这给了我错误:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)照亮\ View \ Engines \ PhpEngine :: main():无法打开 '/Users/Username/Sites/sitename/storage/framework/views/ui/build/index.html' (include_path =': ')

此路径不正确,但我不确定为什么将 / storage / framework / 插入该路径 。

我也有三 编辑以下内容,每个都有类似的错误打开资源失败

require_once('../../ ui / build / index。 HTML '); <代码> require_once($ _ SERVER [' DOCUMENT_ROOT ']。'/ UI /建立/ index.html中'); <代码> require_once(目录名(__ FILE__) 。'/ ui / build / index.html');

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douniuta4783 2018-03-13 17:19
    已采纳

    Laravel does not integrate with Vue, and Laravel Mix is a simple layer on top of Webpack. The default Laravel application ships with Vue scaffolding but removing that is as simple as deleting the files in resources/assets/js and if you wish to use another Javascript library then you can add that into your app.js instead.

    The error you're receiving is because Laravel caches view files, meaning that they're served from the cache directory (which lives in storage/framework) so references like __DIR__ are referencing the cache directory, not the resources directory. You can see this in the documentation:

    You should avoid using the DIR and FILE constants in your Blade views, since they will refer to the location of the cached, compiled view.

    The correct approach to include files into your views with Blade is using the @include directive, e.g:

    @include('ui.build.index')
    

    Also, worth noting, that any time you do need to obtain the path to a file in your Laravel application you should use the base_path and app_path helpers.

    Prior to continuing with development of your application you should read through the JavaScript & CSS Scaffolding documentation and the Blade documentation, as they contain a lot of information that will be very useful to you — for example, it explains how to replace Vue with React using a single command.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题