0
私はlaravel + angularjsを使用して完全なcrudを作成していますが、 "edit"部分に問題があります。 その内部サーバーエラー、ので、私はそれが何を意味するのか知らないと私は助け:(悪い英語のため申し訳ありません を必要としています。Laravel + AngularJSで編集
エラーは「localhost/crudtccをGET /公共/ API/V1/colaboradores/editar/3 500(内部サーバーエラー)」
のJavaScriptファイル
app.controller('colaboradoresController', function($scope, $http, API_URL) {
$http.get(API_URL + "colaboradores")
.success(function(response) {
$scope.colaboradores = response;
});
$scope.toggle = function(modalstate, id_colaborador) {
$scope.modalstate = modalstate;
switch (modalstate) {
case 'add':
$scope.form_title = "Novo colaborador";
$scope.colaborador = null;
break;
case 'edit':
$scope.form_title = "Dados do colaborador";
$scope.id_colaborador = id_colaborador;
$http.get(API_URL + 'colaboradores/editar/' + id_colaborador)
.success(function(response) {
console.log(response);
$scope.colaborador = response;
});
break;
default:
break;
}
$('#myModal').modal('show');
}
$scope.save = function(modalstate, id_colaborador) {
var url = API_URL + "colaboradores/salvar";
if (modalstate === 'edit'){
url += "/editar/" + id_colaborador;
}
$http({
method: 'POST',
url: url,
data: $.param($scope.colaborador),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(response) {
console.log(response);
location.reload();
}).error(function(response) {
console.log(response);
alert('Um erro ocorreu. Check a log para mais detalhes.');
});
}
$scope.confirmDelete = function(id_colaborador) {
var isConfirmDelete = confirm('Tem certeza que deseja excluir o registro?');
if (isConfirmDelete) {
$http({
method: 'DELETE',
url: API_URL + 'colaboradores/remover/' + id_colaborador
}).
success(function(data) {
console.log(data);
location.reload();
}).
error(function(data) {
console.log(data);
alert('Falha na exclusão');
});
} else {
return false;
}
}
});
ルートがあなたのように角側のリクエストを書くべき
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get("/colaboradores/gercolaboradores",
function() {
return view("/colaboradores/gerenciarcolaboradores");
});
Route::get("/api/v1/colaboradores/","[email protected]");
Route::get("/api/v1/colaboradores/editar/{id_colaborador}","[email protected]");
Route::post('/api/v1/colaboradores/salvar/editar/{id_colaborador}',
'[email protected]');
Route::post('/api/v1/colaboradores/salvar', '[email protected]');
Route::delete('/api/v1/colaboradores/remover/{id_colaborador}', '[email protected]');
?>
で詳しく説明しています。どのようなエラー? 500、404?メッセージ ?ウェブコンソールを使用してください! –
HTMLを追加できますか?また、開発ツールを使用して適切なデバッグ情報を入手してください。通常、ショートカットはctrl + shift + i – TiagoRL
です。申し訳ありませんが、エラーは "http:// localhost/crudtcc/public/api/v1/colaboradores/editar/3 500(内部サーバーエラー)"です。 –