【问题标题】:How to pass variable from blade to LARAVEL commands如何将变量从刀片传递到 LARAVEL 命令
【发布时间】:2018-08-15 16:33:07
【问题描述】:

我需要将刀片中的 user_id 传递给路由,然后将变量用于 laravel 命令。我该怎么办?

lista_lavori.blade.php

<div class="box-tools">
     <a href="/stampasingoloreport/{{$utente->id}}" class="btn btn-box-tool" role="button"><i class="fa fa-print"></i></a>
</div>

web.php - 路由

Route::get('/stampasingoloreport/{id}', function ($id) {
    Artisan::call('StampaSingoloReport:stampasingoloreport');
    return back();
});

StampaSingoloReport.php - 命令

public function handle()
{

    // static id i need to change this dinamically
    $id = 5;
    $utente = \App\User::where('id',$id)->get();

    //invio email per avvertire l'utente
    $data = array('utenti'=>$utente);
    Mail::send('mail.invioMailReportLavoriSingoli', $data, function($message) {
        $message->to('rubertocarmine94@gmail.com', 'Admin Risorse Umane') ->subject('Email da piattaforma BancaStatoHR') ;
        $message->from('rubertocarmine94@gmail.com') ;
    });

}

【问题讨论】:

    标签: laravel laravel-5


    【解决方案1】:

    您可以将数组传递给call() 方法,如

    Route::get('/stampasingoloreport/{id}', function ($id) {
        Artisan::call('StampaSingoloReport:stampasingoloreport',[
          'id' => $id     
     ]);
      return back();
    });
    

    现在在您的 handle 方法中,您可以像访问这些参数一样

    protected $signature = 'StampaSingoloReport:stampasingoloreport { id } ' ;
    
    function handle(){
      $this->argument('id');
     // your code
    }
    

    希望对你有帮助

    【讨论】:

    • levaral 我收到此错误“id”参数不存在。
    • @CarmineRub 您使用过答案中提供的代码吗?
    • 左旋是,但不工作!你能告诉我刀片中的 href="" 吗?请。
    • Artisan::call('StampaSingoloReport:stampasingoloreport',[ 'id' => $id ]);此代码将使用参数运行命令
    • 函数句柄(){ $this->argument('id'); // 你的代码 } 这个函数将接收参数
    猜你喜欢
    • 2022-01-01
    • 2022-11-02
    • 1970-01-01
    • 2019-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多