I'm having a strange behaviour with deleting model records. I have a table where I select records and I pass the ID's to a route for deleting them. This works OK in local environment but in server environment is not working, I'm recieving the following exception message:Class 'App\OfferDemand' not found
It looks like in server environment, it's failing due to some array issue? Does anyone can help me?
Regards!
This is local environment request extracted from Telescope:
{
"ids": [
"6",
"5"
]
}
This is server environment request extracted from Telescope:
{
"ids": [
"3",
"2"
]
}
This is the Route:
Route::post('/processes/offerdemand/delete/', 'OfferDemandController@delete')->name('processes.offerdemand.delete')->middleware('auth');
This is the Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use App\OfferDemand;
use App\User;
use App\Property;
use SearchHelper;
use DB;
class OfferDemandController extends Controller
{
public function delete(Request $request)
{
$ids = $request->ids;
try {
foreach ($ids as $id) {
$offerdemanddelete = OfferDemand::findOrFail($id);
$offerdemanddelete->offerdemandslocations()->delete();
$offerdemanddelete->offerdemandsattributes()->delete();
$offerdemanddelete->offerdemandsmatchs()->delete();
$offerdemanddelete->delete();
}
return response()->json([
'status' => 200
]);
} catch (\Exception $ex) {
return response()->json([
'status' => 500,
'message' => $ex->getMessage()
]);
}
}
}
This is the AJAX call:
var selectedDelete = function () {
$('#kt_subheader_group_actions_delete_all').on('click', function () {
// fetch selected IDs
var ids = [];
var ids = datatable.rows('.kt-datatable__row--active').nodes().find('.kt-checkbox--single > [type="checkbox"]').map(function (i, chk) {
return $(chk).val();
});
var idstodelete = ids.get();
console.log(idstodelete);
if (ids.length > 0) {
// learn more: https://sweetalert2.github.io/
swal.fire({
buttonsStyling: false,
text: "¿Esta seguro que desea eliminar los registros seleccionados?",
type: "danger",
confirmButtonText: "Si, eliminar!",
confirmButtonClass: "btn btn-sm btn-bold btn-danger",
showCancelButton: true,
cancelButtonText: "No, cancelar",
cancelButtonClass: "btn btn-sm btn-bold btn-brand"
}).then(function (result) {
if (result.value) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: 'POST',
url: '/processes/offerdemand/delete',
data: { ids: idstodelete },
dataType: 'JSON',
success: function (data) {
var url = window.location.origin;
var link = '/processes/offerdemand';
var completeurl = url + link;
if (data.status != 200) {
console.log(data.status);
swal.fire({
"title": "",
"text": "Ocurrió un error, contactar al administrador",
"type": "error",
showConfirmButton: !1,
timer: 2000,
onClose: () => {
window.location.href=completeurl
}
});
} else {
swal.fire({
"title": "",
"text": "Se ha eliminado correctamente!",
"type": "success",
showConfirmButton: !1,
timer: 2000,
onClose: () => {
window.location.href=completeurl
}
});
}
}
})
var xhr = $.ajax();
console.log(xhr)
}
});
}
});
}
This is the exception:
{
"message": "Class 'App\OfferDemand' not found",
"exception": "Symfony\Component\Debug\Exception\FatalThrowableError",
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/app/Http/Controllers/OfferDemandController.php",
"line": 22,
"trace": [
{
"function": "delete",
"class": "App\Http\Controllers\OfferDemandController",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
"line": 54,
"function": "call_user_func_array"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
"line": 45,
"function": "callAction",
"class": "Illuminate\Routing\Controller",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
"line": 219,
"function": "dispatch",
"class": "Illuminate\Routing\ControllerDispatcher",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
"line": 176,
"function": "runController",
"class": "Illuminate\Routing\Route",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 681,
"function": "run",
"class": "Illuminate\Routing\Route",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 130,
"function": "Illuminate\Routing\{closure}",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
"line": 41,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Routing\Middleware\SubstituteBindings",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php",
"line": 43,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Auth\Middleware\Authenticate",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php",
"line": 76,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\VerifyCsrfToken",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php",
"line": 49,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\View\Middleware\ShareErrorsFromSession",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php",
"line": 56,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Session\Middleware\StartSession",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php",
"line": 37,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php",
"line": 66,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Cookie\Middleware\EncryptCookies",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 105,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 683,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 658,
"function": "runRouteWithinStack",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 624,
"function": "runRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
"line": 613,
"function": "dispatchToRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 177,
"function": "dispatch",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 130,
"function": "Illuminate\Foundation\Http\{closure}",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/spatie/laravel-cors/src/Cors.php",
"line": 28,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Spatie\Cors\Cors",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line": 21,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\TransformsRequest",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
"line": 21,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\TransformsRequest",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
"line": 27,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\ValidatePostSize",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php",
"line": 62,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/fideloper/proxy/src/TrustProxies.php",
"line": 57,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 171,
"function": "handle",
"class": "Fideloper\Proxy\TrustProxies",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
"line": 105,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 152,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
"line": 117,
"function": "sendRequestThroughRouter",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "/opt/bitnami/apps/kiwidev/htdocs/kw-plataforma/public/index.php",
"line": 55,
"function": "handle",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
}
]
}
This is the model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class Offerdemand extends Model
{
protected $fillable = [
'user_id',
'prop_search_name',
'prop_search_expiration',
'prop_expired',
'prop_transaction',
'prop_type',
'prop_currency',
'prop_price_from',
'prop_price_to',
'email'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function offerdemandslocations()
{
return $this->hasMany(Offerdemandslocations::class);
}
public function offerdemandsattributes()
{
return $this->hasMany(Offerdemandsattribute::class);
}
public function offerdemandsmatchs()
{
return $this->hasMany(Offerdemandsmatchs::class);
}
public function del_offermatches(){
$this->offerdemandsmatchs()->delete();
}
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/33qVfpn
via IFTTT
Aucun commentaire:
Enregistrer un commentaire