简体   繁体   English

如何从laravel控制器调用放置在laravel文件夹之外的php文件

[英]How to call php files placed outside laravel folder from laravel controller

I have laravel project on my localhost the name is blog , and I have some php files in tmrate folder which is located oulside the blog 我在我的localhost上有laravel项目名称是博客,我在tmrate文件夹中有一些php文件,位于博客的另一端

path for laravel project- www/blog
path for php files -www/tmrate/.php files

I write following route: 我写下面的路线:

Route::get('/tmrate/{id}','WebServiceController@getTmrate');
Route::post('/tmrate/{id}','WebServiceController@postTmrate');

In WebServiceController I have following code, 在WebServiceController中我有以下代码,

public function getTmrate($id){
    $tmrate=DB::table('team_rating')->where('teamId',$id)->first();
        if($tmrate->rating==''){
             return view('tmrate.rateUs')->with('tmrate',$tmrate);
        }else{
         return view('tmrate.alreadyRatedUs');
        }
    }

whenever I put tmrate folder in resources/views it is working fine , but I want to place tmrate folder outsisde project folder and return view something like this 每当我在资源/视图中放置tmrate文件夹它工作正常,但我想将tmrate文件夹放在outsisde项目文件夹中并返回类似这样的视图

return view('www.tmrate.rateUs') or ('www.tmrate.rateUs.php')

But It wasn't working do you have any suggestions. 但它没有用,你有什么建议吗?

You have to set (in config/view.php file) the second path where the Laravel should look for your views. 您必须在(在config / view.php文件中)设置Laravel应查找视图的第二个路径。 The order is important , the framework will check paths from the first to the last element in the above array (so you can have views in both folders, but the first matching will be used). 顺序很重要 ,框架将检查上面数组中从第一个元素到最后一个元素的路径(因此您可以在两个文件夹中都有视图,但将使用第一个匹配)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM