首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从laravel 8的特征返回视图($viewVariable)

从laravel 8的特征返回视图($viewVariable)
EN

Stack Overflow用户
提问于 2021-06-05 16:27:00
回答 1查看 234关注 0票数 0

我有一个特征,由几个控制器在laravel 8中调用。每个控制器都给出返回视图的名称,并在该属性上具有函数。如果我在这个特征中做了一个dd($viewVariable);,那么我就看到了对视图的正确参考。但这一特点拒绝退让。它只是给了我一个空白的屏幕。首先,我认为“没有引号”、“单引号”或“哑巴引号”都有问题,但我尝试了每一种变体,但都没有成功。

我试着用正常的方式设置视图,但它甚至拒绝渲染。我已经用dd($var);检查了其他函数和变量,直到返回视图为止,一切都是正确的。

ChartTrait.php

代码语言:javascript
复制
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);
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-05 16:40:27

ChartTrait.php中的函数没有什么问题。问题出在控制员身上。您需要return调用的函数来呈现视图。

正确称呼特质的方式

代码语言:javascript
复制
    public function index()
    {
        $view = "".'content.export.export'."";
        return $this->setViewOptionsForChartGeneration($view);
    }

用错误的方式称呼这种特质

代码语言:javascript
复制
    public function index()
    {
        $view = "".'content.export.export'."";
        $this->setViewOptionsForChartGeneration($view);
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67851633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档