you could pass the values through as parameters.
$this->sendsms($test1->courier);
---------------------------------------------------
public function sendsms($message='')
{
.
.
.
Id probably even look into extracting this into its own class.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
HI, i am sending messages to customers from an api. so i created a trait. but in message i need to send dynamic data , i dont know how to take that message from controller and to pass trait. here is my controller code.
public function add()
{
$test1 = device::where('id', Input::get('id'))->firstOrFail();
$test1->courier = Input::get('courier');
$test1->track = Input::get('track');
$test1->status = '4';
$test1->save();
$test1 = $this->sendsms();
Alert::success('Data successfully stored');
return redirect('readytoship');
}
from the above controller i need to take courier value and track value and i want to send that values to sendsms method in SmsTrait. my SmsTrait code is
trait SmsTrait {
public function sendsms()
{
// Account details
$username = '********************';
$hash = '**********************************';
// Message details
$numbers = array(*************);
$sender = urlencode('**************');
$message = rawurlencode('My message ');
$numbers = implode(',', $numbers);
// Prepare data for POST request
$data = array('username' => $username, 'hash' => $hash, 'numbers' => $numbers, "sender" => $sender, "message" => $message);
$ch = curl_init();
// Send the POST request with cURL
$ch = curl_init('http://api.textlocal.in/send/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// Process your response here
echo $response;
}
}
In $message i want to send the courier and track details
Please or to participate in this conversation.