Я не могу найти способ удалить мои новости. Он возвращает мне ошибку 404 (не найден).Laravel 4 удаление по id
моя модель (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's PHP). У меня есть такая же функция, чтобы удалить мою учетную запись, и она работает.
К какому URL-адресу вы обращаетесь? – rmobis
@Raphael_ это кнопка: ' Delete' – dinomuharemagic
Вы пытаетесь перенаправить на 'NewsController @ delete', но то, что вы действительно хотите, это' AdminController @ news_delete'. – rmobis