亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

拉拉維爾新星 v2.8.0 : 自定義動作標簽

拉拉維爾新星 v2.8.0 : 自定義動作標簽

PHP
慕森王 2022-09-12 13:09:29
有沒有一種簡單的方法來自定義我的資源概述的操作標簽?產品資源//App\Nova\Product.phpnamespace App\Nova;use Illuminate\Http\Request;use App\Nova\Actions\UploadProdcuts as UploadProdcuts;class Product extends Resource{    //...    /**     * Get the actions available for the resource.     *     * @param  \Illuminate\Http\Request  $request     * @return array     */    public function actions(Request $request)    {        return [            new UploadProdcuts        ];    }}上傳產品操作//App\Nova\Actions\UploadProdcuts.phpnamespace App\Nova\Actions;use Illuminate\Bus\Queueable;use Laravel\Nova\Actions\Action;use Illuminate\Support\Collection;use Laravel\Nova\Fields\ActionFields;use Illuminate\Queue\SerializesModels;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Contracts\Queue\ShouldQueue;use Laravel\Nova\Fields\File;use App\Imports\ProductsImport;use Maatwebsite\Excel\Facades\Excel;class UploadProdcuts extends Action{    use InteractsWithQueue, Queueable, SerializesModels;    //public $onlyOnDetail = true;    //public $onlyOnIndex = true;    /**     * Perform the action on the given models.     *     * @param  \Laravel\Nova\Fields\ActionFields  $fields     * @param  \Illuminate\Support\Collection  $models     * @return mixed     */    public function handle(ActionFields $fields, Collection $models)    {        Excel::import(new ProductsImport, request()->file('file'));        return Action::message('Products Uploaded Successfully!');    }    /**     * Get the fields available on the action.     *     * @return array     */    public function fields()    {        return [            File::make('File')->rules('required', 'max:50000', 'mimetypes:application/csv,application/excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'),        ];    }}
查看完整描述

1 回答

?
catspeake

TA貢獻1111條經驗 獲得超0個贊

可以在類中設置屬性,也可以添加函數。如果您查看Nova的操作類(供應商/拉拉維爾/新星/src/操作/操作.php)中的函數:$namename


/**

 * Get the displayable name of the action.

 *

 * @return string

 */

public function name()

{

    return $this->name ?: Nova::humanize($this);

}

因此,您可以在類中設置一個屬性,如下所示:


class UploadProdcuts extends Action

{

    public $name = 'My Action';

}

或者只需添加以下函數:name


/**

 * Get the displayable name of the action.

 *

 * @return string

 */

public function name(): string

{

    return __('My Action Name');

}

旁注,您的類名中有一個拼寫錯誤。您已將其命名為 。UploadProdcutsUploadProducts


查看完整回答
反對 回復 2022-09-12
  • 1 回答
  • 0 關注
  • 93 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號