преобразование массива в строку в Nova

#laravel #laravel-nova

#laravel #laravel-nova

Вопрос:

Я пытаюсь преобразовать массив в строку, используя функцию implode внутри ресурса nova, и она работает нормально, но когда я пытаюсь загрузить тот же файл, отображается ошибка » implode() : передан недопустимый аргумент»..

Вот мой файл ресурсов Nova ..

SubscriptionPlanReport.php :

     <?php

namespace AppNova;

use IlluminateHttpRequest;
use LaravelNovaFieldsID;
use LaravelNovaFieldsText;
use LaravelNovaFieldsNumber;
use NovaItemsFieldItems;
use LaravelNovaHttpRequestsNovaRequest;
use MaatwebsiteLaravelNovaExcelActionsDownloadExcel;

class SubscriptionPlanReport extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = AppSubscriptionPlanMgmt::class;

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'id';

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id',
    ];

    /**
     * Get the fields displayed by the resource.
     *
     * @param  IlluminateHttpRequest  $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('Name','name')->sortable(),
            Text::make('Plan Type','type'),
            Number::make('Price','price')->sortable(),
            Text::make('Validity','validity')->sortable(),
            Text::make('Features','feature',function(){
                return implode(",",$this->feature); //converting array to string
            }),
        ];
    }

    /**
     * Get the cards available for the request.
     *
     * @param  IlluminateHttpRequest  $request
     * @return array
     */
    public function cards(Request $request)
    {
        return [];
    }

    /**
     * Get the filters available for the resource.
     *
     * @param  IlluminateHttpRequest  $request
     * @return array
     */
    public function filters(Request $request)
    {
        return [];
    }

    /**
     * Get the lenses available for the resource.
     *
     * @param  IlluminateHttpRequest  $request
     * @return array
     */
    public function lenses(Request $request)
    {
        return [];
    }

    /**
     * Get the actions available for the resource.
     *
     * @param  IlluminateHttpRequest  $request
     * @return array
     */
    public function actions(Request $request)
    {
        return [
         (new DownloadExcel)->askForWriterType([
            MaatwebsiteExcelExcel::CSV => __('CSV document'), 
            MaatwebsiteExcelExcel::DOMPDF => __('PDF document'),
        ])->withHeadings(),
     ];
 }
    //hiding Create organization report option
 public static function authorizedToCreate(Request $request)
 {
    return false;
}
    //hiding Update option
public function authorizedToUpdate(Request $request)
{
    return false;
}
public static $group = 'Reports';
}
  

введите описание изображения здесь

Заранее благодарю

Комментарии:

1. опубликуйте свой файл ‘ App SubscriptionPlanMgmt:: class’

2. можете ли вы показать какой-нибудь пример того, что находится в вашем $this-> feature, показать дамп $this-> feature

3. Используйте gettype , is_array и is_string , чтобы убедиться feature , что поле имеет тип, который будет способен его обрабатывать. Вы также можете использовать преобразование feature поля в массив в вашей модели.