这件事让我难过。
我收到此错误/反映异常 - > Class App \ Providers \ App \ Campaign不存在
Campaign是为该应用程序创建的类。
奇怪的是,当我使用" show"资源路线。当我使用"索引"列出它时路线。我没有错。
这是班级:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Campaign extends Model
{
protected $table='campaigns';
protected $primaryKey = 'campaignID';
protected $fillable = [
'campaignID',
'campaignName',
'shortDescription',
'longDescription',
];
public function company(){
return $this->belongsTo('App\Company','companyID','companyID');
}
public function person(){
return $this->belongsTo('App\Person','campaignID','campaignID');
}
}
以及" show"来自控制器的功能
public function show(Campaign $campaign)
{
$campaign = Campaign::find($campaign->campaignID);
return view('campaigns.show', ['campaign'=>$campaign]);
}
编辑 - 这是整个控制器
<?php
namespace App\Http\Controllers;
use App\Campaign;
use App\User;
use App\Company;
use App\Lead;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
class CampaignsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$campaigns=Campaign::get();
return view('campaigns.index', ['campaigns'=> $campaigns]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('campaigns.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$coID = Auth::user()->companyID;
$uID = Auth::user()->id;
$campaign = Campaign::create([
'campaignName' => $request->input('campaignName'),
'shortDescription' => $request->input('shortDescription'),
'longDescription' => $request->input('longDescription'),
]);
if($campaign){
$campaigns=Campaign::where('companyID',Auth::User()->companyID)->get();
return view('campaigns.index', ['campaigns'=> $campaigns])
->with('success' , 'Campaign created successfully');
}
return back()->withInput()->with('errors', 'Error creating new campaign');
}
/**
* Display the specified resource.
*
* @param \App\Campaign $campaign
* @return \Illuminate\Http\Response
*/
public function show(Campaign $campaign)
{
$campaign = Campaign::find($campaign->campaignID);
return view('campaigns.show', ['campaign'=>$campaign]);
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Campaign $campaign
* @return \Illuminate\Http\Response
*/
public function edit(Campaign $campaign)
{
$campaign = Campaign::find($campaign->campaignID)->toSQL();
dd($campaign);
return view('campaigns.edit', ['campaign'=>$campaign]);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Campaign $campaign
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Campaign $campaign)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Campaign $campaign
* @return \Illuminate\Http\Response
*/
public function destroy(Campaign $campaign)
{
//
}
public function listcompanycampaigns()
{
$campaigns=Campaign::where('companyID',Auth::User()->companyID)->get();
return view('campaigns.index', ['campaigns'=> $campaigns]);
}
public function listambassadorcampaigns()
{
$campaigns = Campaign::get();
return view('campaigns.ambassadorindex', ['campaigns'=> $campaigns]);
}
我已经清除了缓存和&#34; composer dump-autoload&#34;无济于事。
感谢你们给予的任何帮助。
Jeeves的
答案 0 :(得分:0)
您的路线是什么样的?你在使用路由模型绑定吗?
如果你是,那么你应该先了解它的工作原理:
https://laravel.com/docs/5.6/routing#route-model-binding
否则,删除show
方法中的typehint,并在find方法中使用实际整数查找模型。