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

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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?