dqrnskni67375
2017-10-26 10:16
浏览 150
已采纳

Laravel 5.5传递变量到子控制器返回总是null?

I have a main controller CmsController, wich is extended to default laravel controller:

use App\Http\Controllers\Controller;
class CmsController extends Controller
{
    protected $web = null;

    public function __construct(Request $request)
    {
        $this->web = Web::domain($request->domain)->first();
    }
}

Now, in this controller I want to call $this->web

use App\Http\Controllers\Web\PageController;
class PageController extends CmsController
{
    public function getPage(Request $request)
    {
        dd($this->web); // returns always null
    }
}

The data that should be returned is 100% correct, reqest params are also there...

Can someone give me a idea, what I did wrong here?

图片转代码服务由CSDN问答提供 功能建议

我有一个主控制器CmsController,它扩展到默认的laravel控制器: < pre> 使用App \ Http \ Controllers \ Controller; class CmsController扩展Controller { protected $ web = null; public function __construct(Request $ request) { $ this- &gt; web = Web :: domain($ request-&gt; domain) - &gt; first(); } }

现在,在此 controller我想调用 $ this-&gt; web

 使用App \ Http \ Controllers \ Web \ PageController; 
class PageController扩展CmsController 
  {
公共函数getPage(请求$请求)
 {
 dd($ this-&gt; web);  //返回始终为null 
} 
} 
   
 
 

应返回的数据是100%正确,reqest params也在那里......

有人可以给我一个想法吗,我在这里做错了什么?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题