Open Rinze-Smits opened 6 months ago
@Rinze-Smits Thank you very much for using the package.
Could you write what version of the packages you are using and post an example of use so that I can repeat the same problem myself and solve it
@kongulov Thank you so much for making the package!
The versions I use are all the latest as of now.
kongulov/nova-tab-translatable 2.1.3 spatie/laravel-translatable 6.6.1 laravel/nova 4.32.15 laravel/framework v10.46.0
Model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class TestModel extends Model
{
use HasFactory;
use HasTranslations;
public $translatable = ['test_file'];
}
Migration:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('test_models', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->json('test_file');
});
}
public function down(): void{Schema::dropIfExists('test_models');}
};
Resource:
<?php
namespace App\Nova;
use Kongulov\NovaTabTranslatable\NovaTabTranslatable;
use Kongulov\NovaTabTranslatable\TranslatableTabToRowTrait;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;
class TestModel extends Resource
{
use TranslatableTabToRowTrait;
public static $model = \App\Models\TestModel::class;
public static $title = 'id';
public static $search = ['id',];
public function fields(NovaRequest $request)
{
return [
ID::make()->sortable(),
NovaTabTranslatable::make([
\Laravel\Nova\Fields\File::make('test_file'),
])
];
}
public function cards(NovaRequest $request){return [];}
public function filters(NovaRequest $request){return [];}
public function lenses(NovaRequest $request){return [];}
public function actions(NovaRequest $request){return [];}
}
After creating a record with a file and going to the detail page there is a download link with the file. Clicking it shows the browser download dialog with download.htm and a message saying there is no file.
I have a translatable File field showing on a detail page. The resource uses TranslatableTabToRowTrait. When I try to download the file an error is returned.
I have found the error to be caused by the download being passed to the regular Nova FieldDownloadController (because the field isn't copied with the locale appended in the handler as would happen without TranslatableTabToRowTrait) and the regular FieldDownloadController gets a list of all downloadableFields by checking which fields from availableFieldsOnIndexOrDetail() implement the Downloadable contract. The file field is not in that list.
To fix I suggest also implementing availableFieldsOnIndexOrDetail() or the methods it calls in TranslatableTabToRowTrait.