doufei2007 2015-03-24 15:34
浏览 32

雄辩,删除不工作,Laravel 5

i'm working on a web app using eloquent and laravel 5. The problem is that i'm trying to delete a row of a table called "Ponderacion" but when i send the ajax delete request, the server stops (it stops the execution of the routed function but the server keeps running) at the line where the delete is, without throwing any errors.

Here is the Model of Ponderacion:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Ponderacion extends Model{
    protected $table = 'Ponderacion';
    protected $fillable = array('ponderacionidearea', 'ConfiguracionDeExamenifconf', 'peso');
    public $timestamps = false;
}

Here is the function in the Controller:

public function deleteConfig(Request $request){
            error_log('deleting');
            $s_area = Area::where('nombre', '=', $request->input('s_area'))->first();
            error_log(count($s_area->Configuracion->first()->Ponderacion));
            //DB::statement('delete from Ponderacion where idponderacion = 22');
            foreach ($s_area->Configuracion->first()->Ponderacion as $ponderacion){

                error_log($ponderacion->peso);
                try{
                    $ponderacion->delete();
                }catch(Exception $e){
                    error_log('failure');
                }
            }
            //$s_area->Configuracion->first()->Ponderacion->delete();
            error_log('succesfully deleted');
            $s_area->Configuracion->first()->delete();

        }

I can succesfully print the property "peso" of ponderacion but i'm unable to delete it. Ponderacion has Foreign Keys to other table but no other table has a reference to Ponderacion. I'm able to delete a row of Ponderacion with DB::statement but that is not secure.Succesfully deleted never shows on console.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongyipa0028 2015-03-25 20:39
    关注

    For AJAX testing, I always prefer to directly test via a GET request first where possible and then layer on the AJAX POST once I know the underlying code works.

    In this case, the server is likely throwing a Fatal Error, which will then return a 500 error for an AJAX request and no further information. There is a good SO question that deals with catching Fatal Errors.

    I would check your includes for your class. In Laravel 5, the default namespace is not the global namespace for Controllers. You'll need to add a \ before Exception or add use Exception to the top of your class file.

    Two tips as well:

    • Use SoftDeletes on your model. It's better to track and audit your database records if you never really remove a row. DB storage space is really cheap and Laravel will automatically skip the deleted rows when querying.
    • Use an IDE for development. A lot of these errors can be caught before run-time by a good compiler.
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看