diff --git a/routes/api.php b/routes/api.php index 82cdc96..222a0fe 100644 --- a/routes/api.php +++ b/routes/api.php @@ -3,6 +3,6 @@ use Illuminate\Support\Facades\Route; // Fields... -Route::get('/nova-api/{resource}/{resourceId}/download/{field}', 'FieldDownloadController@show')->where('field', 'translations_(.*)_(.*)'); -Route::delete('/nova-api/{resource}/{resourceId}/field/{field}', 'FieldDestroyController@handle')->where('field', 'translations_(.*)_(.*)'); -Route::delete('/nova-api/{resource}/{resourceId}/{relatedResource}/{relatedResourceId}/field/{field}', 'PivotFieldDestroyController@handle')->where('field', 'translations_(.*)_(.*)'); +Route::get('/nova-api/{resource}/{resourceId}/download/{field}', 'FieldDownloadController@show'); +Route::delete('/nova-api/{resource}/{resourceId}/field/{field}', 'FieldDestroyController@handle'); +Route::delete('/nova-api/{resource}/{resourceId}/{relatedResource}/{relatedResourceId}/field/{field}', 'PivotFieldDestroyController@handle'); diff --git a/src/Http/Controllers/FieldDestroyController.php b/src/Http/Controllers/FieldDestroyController.php index 5f06347..5856462 100644 --- a/src/Http/Controllers/FieldDestroyController.php +++ b/src/Http/Controllers/FieldDestroyController.php @@ -23,7 +23,11 @@ public function handle(NovaRequest $request): \Illuminate\Http\Response $fieldNameArray = array_slice($explode, 1, -1); $fieldName = implode('_', $fieldNameArray); - if (!in_array($fieldName, $resource->translatable)) abort(404); + if (!in_array($fieldName, $resource->translatable)){ + $controller = new \Laravel\Nova\Http\Controllers\FieldDestroyController; + + return $controller($request); + } $resource->authorizeToUpdate($request); $model = $resource->model(); diff --git a/src/Http/Controllers/FieldDownloadController.php b/src/Http/Controllers/FieldDownloadController.php index bef6685..5d9703e 100644 --- a/src/Http/Controllers/FieldDownloadController.php +++ b/src/Http/Controllers/FieldDownloadController.php @@ -2,8 +2,8 @@ namespace Kongulov\NovaTabTranslatable\Http\Controllers; -use Illuminate\Http\Response; use Illuminate\Routing\Controller; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; use Kongulov\NovaTabTranslatable\NovaTabTranslatable; use Laravel\Nova\Http\Requests\NovaRequest; @@ -15,7 +15,7 @@ class FieldDownloadController extends Controller * Download the given field's contents. * * @param \Laravel\Nova\Http\Requests\NovaRequest $request - * @return BinaryFileResponse + * @return \Laravel\Nova\Http\Controllers\FieldDownloadController|BinaryFileResponse * @throws \Illuminate\Auth\Access\AuthorizationException * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ @@ -28,7 +28,11 @@ public function show(NovaRequest $request) $fieldNameArray = array_slice($explode, 1, -1); $fieldName = implode('_', $fieldNameArray); - if (!in_array($fieldName, $resource->translatable)) abort(404); + if (!in_array($fieldName, $resource->translatable)) { // not translatable file + $controller = new \Laravel\Nova\Http\Controllers\FieldDownloadController; + + return $controller($request); + } $resource->authorizeToView($request); $model = $resource->model();