我有一个特征,由几个控制器在laravel 8中调用。每个控制器都给出返回视图的名称,并在该属性上具有函数。如果我在这个特征中做了一个dd($viewVariable);,那么我就看到了对视图的正确参考。但这一特点拒绝退让。它只是给了我一个空白的屏幕。首先,我认为“没有引号”、“单引号”或“哑巴引号”都有问题,但我尝试了每一种变体,但都没有成功。
我试着用正常的方式设置视图,但它甚至拒绝渲染。我已经用dd($var);检查了其他函数和变量,直到返回视图为止,一切都是正确的。
ChartTrait.php
public function setViewOptionsForChartGeneration($viewVariable)
{
// Check which role the user has in the application
if (Auth::user()->hasRole('admin')) {
$recorderCollection = $this->getRecorderCollectionWhenAdmin();
return view($viewVariable)->withRecorderCollection($recorderCollection);
} elseif (Auth::user()->hasRole('employee|user')) {
// Get all the valid timeslots that belongs to the authenticated user
$userTimeslotCollection = $this->getUserTimeslot();
// Get all the corresponding recorders from the valid timeslots that belongs to the authenticated user
$recorderCollection = $this->onlyCollectRecordersBasedOnValidTimeslot($userTimeslotCollection);
// return the view with all the possibility's the authenticated user has.
return view($viewVariable)
->withRecorderCollection($recorderCollection->flatten())
->withUserTimeslotCollection($userTimeslotCollection);
}
}发布于 2021-06-05 16:40:27
ChartTrait.php中的函数没有什么问题。问题出在控制员身上。您需要return调用的函数来呈现视图。
正确称呼特质的方式
public function index()
{
$view = "".'content.export.export'."";
return $this->setViewOptionsForChartGeneration($view);
}用错误的方式称呼这种特质
public function index()
{
$view = "".'content.export.export'."";
$this->setViewOptionsForChartGeneration($view);
}https://stackoverflow.com/questions/67851633
复制相似问题