简体   繁体   English

未定义的属性

[英]Undefined property

I'm trying to create a CRUD on my model, but I'm getting this error: 我正在尝试在模型上创建CRUD,但是出现此错误:

Undefined property: App\\Http\\Controllers\\MarketingChannelController::$MarketingChannelRepository 未定义的属性:App \\ Http \\ Controllers \\ MarketingChannelController :: $ MarketingChannelRepository

On this funciton: 在此功能上:

 public function edit($id)
    {
        //

        return view('MarketingChannel.create', [
            'MarketingChannel' => $this->MarketingChannelRepository->getMarketingChannel($id),
        ]);
    }

This is my MarketingChannelRepository: 这是我的MarketingChannelRepository:

<?php

namespace App\Repositories;

use App\MarketingChannel;

class MarketingChannelRepository
{
    /**
     * Get all of the tasks for a given user.
     *
     * @param  User  $user
     * @return Collection
     */
    public function allMarketingChannels()
    {
        return MarketingChannel::orderBy('id', 'asc')
                    ->get();
    }

    public function getMarketingChannel($id)
    {
        return MarketingChannel::where('id', $id)
                    ->orderBy('id', 'asc')
                    ->get();
    }

}

?>

The Controller needs the repository variable. Controller需要存储库变量。

Example: 例:

class MarketingChannelController extends Controller{
    protected $MarketingChannelRepository;

    public function __construct(MarketingChannelRepository $MarketingChannelRepository){
     $this->MarketingChannelRepository = $MarketingChannelRepository;
    }
    public function edit($id)
    {


        return view('MarketingChannel.create', [
        'MarketingChannel' => $this->MarketingChannelRepository->getMarketingChannel($id),
    ]);
    }
}

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

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