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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里