Skip to content

Commit

Permalink
Fixed issue #26 (Package overrides some of default nova routes)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongulov committed Oct 21, 2022
1 parent 7927304 commit b5face5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 3 additions & 3 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
6 changes: 5 additions & 1 deletion src/Http/Controllers/FieldDestroyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 7 additions & 3 deletions src/Http/Controllers/FieldDownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand All @@ -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();
Expand Down

0 comments on commit b5face5

Please sign in to comment.