Closed phoenixg closed 5 years ago
i have the same error, i used macos mojave.
@sabid I used macos mojave too.
@sabid @phoenixg Could you provide more information? I cannot reconstruct this error.
@Sparclex I was using the latest version of Nova v1.1.17 and I did no customization.
And what did your resource and your import file look like?
@Sparclex Here it is:
Resource:
<?php
namespace App\Nova;
use \Phx\Model\Dashboard\Import;
use App\Utils\Permission\Permission;
use Illuminate\Support\Facades\Auth;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Image;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;
use Maatwebsite\LaravelNovaExcel\Actions\DownloadExcel;
class Import extends Resource
{
public static $category = "operation";
public static $indexDefaultOrder = ['created_at' => 'desc'];
public static function label()
{
return 'import';
}
public static $displayInNavigation = true;
public static $globallySearchable = false;
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \Phx\Model\Dashboard\Import::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'name';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
ID::make('ID')->sortable(),
Text::make('name', 'name'),
Text::make('company', 'company')
];
}
/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function cards(Request $request)
{
return [
new \Sparclex\NovaImportCard\NovaImportCard(\Phx\Model\Dashboard\Import::class),
];
}
/**
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function filters(Request $request)
{
return [
];
}
/**
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function lenses(Request $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function actions(Request $request)
{
return [
];
}
public static function indexQuery(NovaRequest $request, $query)
{
$query = parent::indexQuery($request, $query);
return $query;
}
}
Import File:
<?php
namespace Phx\Model\Dashboard;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder;
use Pingpp\Model\DashboardModel;
class Import extends MyModel
{
protected $primaryKey = 'id';
protected static $table_name = 'import';
protected $dates = [
'created_at'
];
public $incrementing = true;
protected $guarded = [];
protected $casts = [
];
const CREATED_AT = 'created_at';
}
I see you passed the model instead of the resource as parameter. Try changing this line
new \Sparclex\NovaImportCard\NovaImportCard(\Phx\Model\Dashboard\Import::class),
to this
new \Sparclex\NovaImportCard\NovaImportCard(self::class),
I think I will type hint this as a nova resource in a future version
Just remembered this is a string, so no type hinting
@Sparclex I followed your solution and tried again, still meet that error.
My uploaded CSV file content is equal to my MySQL table structure:
upload-sample.csv
id,name, company, remark, source_name, mobile
111,phx, test,test,test,test
I tried to watch ls /private/var/tmp/
, and the temporary file existed and disappeared very quickly, seems the file was deleted after uploaded.
I'm using Laravel v5.7.12
update How I find the resource is successfully imported into the database, but the file does not exist error still displays.
I can still not reproduce this error, but I made a change which could fix it. Please update and give me some feedback.
@Sparclex It still appears that error, but after I completely removed the code below, that error would disappear:
if (file_exists($this->file->getRealPath())) {
unlink($this->file->getRealPath());
}