雄辩的ORM-更新和删除不起作用 [英] Eloquent ORM - update and delete not working

查看:48
本文介绍了雄辩的ORM-更新和删除不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的第一个Laravel项目开发CRUD.显示和显示项目工作正常.

I am working on CRUD for my first Laravel project. Displaying and showing items is working fine.

我尝试用Query更新条目,以确认我可以更改表中的值并且有效:

I tried to update the entry with Query to confirm that I can change values in the table and it worked:

DB::update("UPDATE seasons SET title = 'foo' WHERE ID = 1");

我的问题是更新或删除条目均无效.

My Problem is that neither updating nor deleting entries will work.

<?php
class SeasonAdminController extends \BaseController
{ 
    // WORKS
    public function store()
    {
        $season = new Season;
        $season->title = Input::get('title');
        $season->save();

        Session::flash('message', 'success!');
        return Redirect::to('backend/season');
    }

    // NOT WORKING
    public function update($id)
    {
        $season = Season::find($id);
        $season->title = Input::get('title');
        $season->save();

        Session::flash('message', 'success!');
        return Redirect::to('backend/season');
    }

    // NOT WORKING
    public function destroy($id)
    {
        Season::destroy($id);

        Session::flash('message', 'success!');
        return Redirect::to('backend/season/');
    }
}

我的路线如下:

Route::resource('backend/season', 'SeasonAdminController');

编辑页面中的表单标签:

The form-tag from the edit page:

{{ Form::model($season, array('route' => array('backend.season.update', $season->ID), 'method' => 'PUT')) }}

用于删除条目的表格:

{{ Form::open(array('url' => 'backend/season/' . $value->ID, 'class' => 'pull-right')) }}
    {{ Form::hidden('_method', 'DELETE') }}
    {{ Form::submit('Löschen', array('class' => 'btn btn-danger')) }}
{{ Form::close() }}

我在这里想念什么.感谢您的帮助,谢谢!

What am I missing here. I appreciate you help, thank you!

推荐答案

错误是我在数据库表中将"ID"而不是"id"作为主键.我不太确定为什么这不起作用,但我想这与Eloquent模型的默认主键有关.

The error was that I had "ID" instead of "id" as a primary key in the database table. I am not quite sure why this should not work, but I guess it has to do with the default primary key from the Eloquent Model.

这篇关于雄辩的ORM-更新和删除不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆