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

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');

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 问题重发,R语言:代码运行过程中出现如下警告,请求如何解决!
  • ¥15 神经网络模型一直不能上GPU
  • ¥15 苍穹外卖拦截器token为null
  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵
  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关