我试图在我的模型上创建一个CRUD,但我收到了这个错误:
未定义属性:App \ Http \ Controllers \ MarketingChannelController :: $ MarketingChannelRepository
在这个功能上:
public function edit($id)
{
//
return view('MarketingChannel.create', [
'MarketingChannel' => $this->MarketingChannelRepository->getMarketingChannel($id),
]);
}
这是我的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();
}
}
?>
答案 0 :(得分:1)
Controller
需要存储库变量。
示例:
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),
]);
}
}