John Davidson

php - i setup email sent on status update (status is in tinyint format) i want to display Status as "in progress" not the tiny int how can i do that?

0 comments
Message:


/TemplateController


    public function invoice_status_upadated(Request $request){ 

$data= Invoice::find($request->id);
$oldstatus = $data->status;
$data->status = $request->status;

$data->save();


$email = Auth::user()->email;
$status = $data->status;
$id = $data->id;


$msg = [
'email' => $email,
'name' => Auth::user()->name,
'oldstatus' => $oldstatus,
'status' => $status,
'id' => $id
];

Mail::send('index.invStatusUpdate', $msg, function($msg) use($email){


$msg->to($email)->subject('Invoice Status has been Changed');});

return redirect('invoices');}

Emails/invStatusUpdate.blade.php



<html>
<body>
<b>Hello {{$name}}<b><br>
<p style="text-align:centre">Invoice ID: {{$id}} has been updated from {{$oldstatus}} to {{$status}} </p><br>
<p>By {{$name}} </p>
</body>
</html>

Result in Email



i want to change these marked tinyint (0 and 1) to "Pending","in Process"


invoices/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>

Results on Status update page



I just want to change the format in the email (0,1,2,3) to (pending, In process, Completed, Cancelled



My Answer:
To display the status in a more readable format, you can create a function that converts the tinyint status value to a human-readable string. Here's an example code snippet:

php
function getStatusText($status) {
switch ($status) {
case 0:
return "Pending";
break;
case 1:
return "Approved";
break;
case 2:
return "Rejected";
break;
default:
return "Unknown";
}
}

// Example usage
$status = 1; // Assuming status is retrieved from database
$statusText = getStatusText($status);
echo "Status: " . $statusText;


In this code snippet, the `getStatusText` function takes the tinyint status value as input and returns a human-readable string based on the status value. You can customize the status text values and add more cases as needed.

Rate this post

3 of 5 based on 8953 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us