array to string conversion in Nova

1.2k views Asked by At

I am trying to convert an array to string using implode function inside nova resource and it's working fine but when i'm trying to download the same file it's showing error that " implode() : invalid argument passed " ..

Here is my Nova Resource file ..

SubscriptionPlanReport.php :

    <?php

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Number;
use NovaItemsField\Items;
use Laravel\Nova\Http\Requests\NovaRequest;
use Maatwebsite\LaravelNovaExcel\Actions\DownloadExcel;

class SubscriptionPlanReport extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = \App\SubscriptionPlanMgmt::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  \Illuminate\Http\Request  $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  \Illuminate\Http\Request  $request
     * @return array
     */
    public function cards(Request $request)
    {
        return [];
    }

    /**
     * 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 [
         (new DownloadExcel)->askForWriterType([
            \Maatwebsite\Excel\Excel::CSV => __('CSV document'), 
            \Maatwebsite\Excel\Excel::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';
}

enter image description here

Thank you in advance

0

There are 0 answers