简体   繁体   中英

i want to send a mail to the currently logged in user when the invoice status is updated/changed how can i do it?

here is my Invoice Status update form

index.blade.php

<td>
    <form action="{{url('/invoice_status_upadated')}}" method="POST">
        <input class="form-control" name="id" type="hidden" value="{{$inv['id']}}">
        {{ csrf_field() }}
        <div class="input-group mb-3">
            <select class="form-select" aria-label="Default select example" name="status">
                <option value="0" {{$inv->status == 0 ? 'selected':''}}>Pending </option>
                <option value="1" {{$inv->status == 1 ? 'selected':''}}>In Process </option>
                <option value="2" {{$inv->status == 2 ? 'selected':''}}>Completed </option>
                <option value="3" {{$inv->status == 3 ? 'selected':''}}>Cancelled </option>
            </select>
        <button type="submit"  class="btn btn-outline-success">Update</button>
        </div>
    </form>
</td>

web.php:

Route::post('/invoice_status_upadated', 'App\Http\Controllers\TemplateController@invoice_status_upadated',)->name('invoice_status_upadated');

TemplateController

public function invoice_status_upadated(Request $request){ 
    $data= Invoice::find($request->id);
    $data->status = $request->status;
    $data->save();
    return redirect('invoices');
}

Now i want to send an email to currently logged in user

Here is what i would do:

   if ($data->status !== $request->status) {
      // Here you can send your email, and set the new status.
      $data->status = $request->status;
    }

You have to check if the status isn't the same, then if it changed, you can put the code you want. First, set the new status, then you can send the email.

Here you can found how to create the mail template and send it: https://laravel.com/docs/9.x/mail

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM