我正在尝试使用__construct设置一些全局变量,但它没有启动,因为我可以在其中写入任何内容并且这些函数不会调用任何错误。我的应用程序中没有City类,但此代码没有错误。为什么呢?
/app/Http/Controller/Controller.php:
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function __construct()
{
$this->data['cities'] = City::get();
}
}
答案 0 :(得分:1)
请按此更改您的构造函数
/* 'stripHTML': returns the concatenated text nodes of the html string provided */
MyApp.filter ('stripHTML', [function () {
return function (stringWithHtml) {
var strippedText = $('<div/>').html(stringWithHtml).text();
return strippedText;
};
}]);
因为我们首先需要调用父构造函数。
希望这有帮助!