我不明白爲什麼我會得到這個錯誤。Laravel 5.2 BadMethodCallException在Controller.php行107:方法[保存]不存在
控制器:SectionHeaderController
<?php
namespace SimpleCms\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Carbon\Carbon;
use App\Http\Requests;
use App\SectionHeader;
class SectionHeaderController extends Controller {
public function store(Request $request) {
$header = new SectionHeader();
$this->validate($request, [
'title' => 'required',
'image' => 'required|mimes:jpeg,png|max:1024|dimensions:max_width=300,max_height=100',
'heading' => 'required',
'description' => 'required'
]);
$header->title = $request->title;
$header->heading = $request->description;
$header->description = $request->description;
if($request->hasFile('image')) {
$file = Input::file('image');
$timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
$name = $timestamp. '-' .$file->getClientOriginalName();
$header->filePath = $name;
$file->move(public_path().'/images/', $name);
}
$header->save();
return $this->create()->with('success', 'Done!');
}
}
型號:SectionHeader
<?php
namespace SimpleCms;
use Illuminate\Database\Eloquent\Model;
class SectionHeader extends Model {
protected $table = 'sectionheader';
protected $fillable = [
'title',
'description',
'heading',
'image'
];
}
路線:
Route::post('/home/store', '[email protected]');
我不知道什麼是錯的,也沒有如何解決這個問題。 這個錯誤出現後,我點擊表格提交指向這[email protected]
任何想法?
謝謝。
編輯: 我每建議改變了,我得到新的錯誤
FatalErrorException在SectionHeaderController.php線34:類 '應用\ SectionHeader' 未找到
我明白你在說什麼,我會改變最後一部分不用擔心,但我可以找出爲什麼我得到這個錯誤 – Morpheus
爲什麼你改變你的問題????????????????? ?? –
將您的模型名稱空間更改爲「App \ SectionHeader」...您的名稱空間爲:SimpleCms ... @Morpheus –