我正在使用雄辩的laravel 5开发一个web应用程序。问题是,我试图删除一个名为"Ponderacion“的表中的一行,但是当我发送ajax删除请求时,服务器停止(停止执行路由函数,但服务器继续运行)在删除的行,没有抛出任何错误。
以下是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;
}以下是主计长的功能:
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();
}我可以成功地打印出ponderacion的属性“比索”,但我无法删除它。Ponderacion拥有指向其他表的Foreign,但没有其他表具有对Ponderacion的引用。我可以用DB::语句删除一行Ponderacion,但这不是secure.Succesfully,删除后,就不会在控制台上显示。
提前谢谢。
发布于 2015-03-25 20:39:41
对于AJAX测试,我总是倾向于先通过GET请求进行直接测试,然后在了解底层代码后再在AJAX POST上进行层测试。
在这种情况下,服务器可能会抛出一个Fatal Error,然后该将为AJAX请求返回500个错误,而没有进一步的信息。有一个很好的关于捕获致命错误的问题。。
我会为你的班级检查你的包括。在Laravel 5中,默认名称空间不是控制器的全局命名空间。您需要在\之前添加Exception,或者将use Exception添加到类文件的顶部。
还有两条建议:
https://stackoverflow.com/questions/29236768
复制相似问题