irankhosravi
4 months ago
43
20
Laravel

How to create send code again?

Posted 4 months ago by irankhosravi

Look at my code

web.php

 Route::post('/send-again-code', '[email protected]')->name('sendAgainCode');

HomeController.php

public function sendAgainCode ()
{
    $code = rand(1000,9999);

    try {
        $api = new \Kavenegar\KavenegarApi("Api Key");
        $sender = "10004346";
        $message  = $code;
        $receptor = auth()->user()->mobile;
        $result = $api->Send($sender, $receptor, $message);
        if ($result) {
            foreach ($result as $r) {
                echo "messageid = $r->messageid";
                echo "message = $r->message";
                echo "status = $r->status";
                echo "statustext = $r->statustext";
                echo "sender = $r->sender";
                echo "receptor = $r->receptor";
                echo "date = $r->date";
                echo "cost = $r->cost";
            }
        }
    } catch (\Kavenegar\Exceptions\ApiException $e) {
        echo $e->errorMessage();
    } catch (\Kavenegar\Exceptions\HttpException $e) {
        echo $e->errorMessage();
    }
}

Please sign in or create an account to participate in this conversation.