我無法找到刪除我的消息的方法。它返回一個404(未找到)錯誤。通過編號刪除Laravel 4
我的模型(News.php):
<?php
class News extends Eloquent {
protected $table = 'aac_news';
protected $fillable = array('author', 'title', 'content');
public $timestamps = true;
}
我的控制器:
<?php
class AdminController extends BaseController {
/**
* News Repository
*
* @var News
*/
protected $news;
public function __construct(News $news)
{
$this->news = $news;
}
/** ------------------------------------------
* News Functions
* ------------------------------------------
*/
public function get_news()
{
return View::make('admin.news_managment')->with('newss', $this->news->all());
}
public function create_news()
{
return View::make('admin.create_news');
}
public function post_create_news()
{
$input = Input::all();
$rules = array(
'author' => 'required|min:4|max:255',
'title' => 'required|unique:aac_news,title|min:4|max:255',
'content' => 'required|unique:aac_news,content|min:10'
);
$validation = Validator::make($input, $rules);
if ($validation->fails()) {
return Redirect::back()->withErrors($validation);
} else {
News::create($input);
return Redirect::to('news/index');
}
}
public function news_delete($newsId)
{
$news = $this->news->findOrFail($newsId);
$news->delete();
return Redirect::back()->with('success', 'Your news post has been deleted.');
}
}
和我的路線:
# News Management
Route::get('admin/dash/news', '[email protected]_news');
Route::get('admin/dash/news/add', '[email protected]_news');
Route::post('admin/dash/news/add', '[email protected]_create_news');
Route::get('admin/dash/news/{id}/delete/', '[email protected]_delete');
它只是返回我的自定義錯誤的404頁。我的控制檯中沒有錯誤(laravel的PHP)。我有相同的功能來刪除我的帳戶,它的工作原理。
您訪問哪個URL? – rmobis
@Raphael_ 這是一個按鈕:' Delete' – dinomuharemagic
您正嘗試重定向到'NewsController @ delete',但是您真正想要的是'AdminController @ news_delete'。 – rmobis