{"id":860,"date":"2025-06-12T01:21:36","date_gmt":"2025-06-11T17:21:36","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/laravel\/860.html"},"modified":"2025-06-12T01:21:36","modified_gmt":"2025-06-11T17:21:36","slug":"laravel%e4%b8%ad%e7%9a%84%e7%9f%ad%e4%bf%a1%e9%80%9a%e7%9f%a5%ef%bc%9a%e5%ae%9e%e7%94%a8%e6%8c%87%e5%8d%97","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/860.html","title":{"rendered":"Laravel\u4e2d\u7684\u77ed\u4fe1\u901a\u77e5\uff1a\u5b9e\u7528\u6307\u5357"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">Bug&#32534;&#35793;&#29422;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#26631;&#39064;&#65306;Laravel&#20013;&#30340;&#30701;&#20449;&#36890;&#30693;&#65306;&#23454;&#29992;&#25351;&#21335;<\/p>\n<p>&#27491;&#25991;&#65306;<\/p>\n<p>&#22312;&#29616;&#20195;&#24212;&#29992;&#24320;&#21457;&#20013;&#65292;&#28040;&#24687;&#36890;&#30693;&#23545;&#20110;&#20445;&#25345;&#29992;&#25143;&#27963;&#36291;&#12289;&#25552;&#21319;&#29992;&#25143;&#20307;&#39564;&#33267;&#20851;&#37325;&#35201;&#12290; Laravel &#26159;&#19968;&#20010;&#24378;&#22823;&#30340; PHP &#26694;&#26550;&#65292;&#25552;&#20379;&#20102;&#20016;&#23500;&#30340;&#21151;&#33021;&#26469;&#22788;&#29702;&#21508;&#31181;&#20219;&#21153;&#65292;&#21253;&#25324;&#30701;&#20449;&#36890;&#30693;&#12290;&#20197;&#19979;&#26159;&#19968;&#20123;&#20851;&#20110;&#22914;&#20309;&#22312; Laravel &#20013;&#23454;&#29616;&#30701;&#20449;&#36890;&#30693;&#30340;&#23454;&#29992;&#25351;&#21335;&#12290;<\/p>\n<h3>1. &#23433;&#35013;&#21644;&#37197;&#32622;<\/h3>\n<p>&#39318;&#20808;&#65292;&#30830;&#20445;&#20320;&#24050;&#32463;&#23433;&#35013;&#20102; Laravel &#24182;&#19988;&#26377;&#19968;&#20010;&#22522;&#26412;&#30340;&#24212;&#29992;&#39033;&#30446;&#12290;&#22914;&#26524;&#27809;&#26377;&#23433;&#35013;&#65292;&#21487;&#20197;&#20351;&#29992; Composer &#36827;&#34892;&#23433;&#35013;&#65306;<\/p>\n<pre><code class=\"language-bash\">composer create-project --prefer-dist laravel\/laravel my-app\ncd my-app<\/code><\/pre>\n<p>&#25509;&#19979;&#26469;&#65292;&#20320;&#38656;&#35201;&#23433;&#35013;&#19968;&#20010; SMS &#26381;&#21153;&#25552;&#20379;&#21830;&#12290;&#36825;&#37324;&#25105;&#20204;&#20197; Twilio &#20026;&#20363;&#65292;&#23427;&#26159;&#19968;&#20010;&#27969;&#34892;&#30340; SMS &#26381;&#21153;&#25552;&#20379;&#21830;&#65292;&#25903;&#25345;&#22810;&#31181;&#32534;&#31243;&#35821;&#35328;&#12290;&#20320;&#21487;&#20197;&#36890;&#36807; Composer &#23433;&#35013; Twilio &#30340; Laravel &#39537;&#21160;&#22120;&#65306;<\/p>\n<pre><code class=\"language-bash\">composer require twilio\/twilio-laravel<\/code><\/pre>\n<p>&#28982;&#21518;&#65292;&#36816;&#34892;&#36801;&#31227;&#21629;&#20196;&#26469;&#21019;&#24314;&#24517;&#35201;&#30340;&#25968;&#25454;&#24211;&#34920;&#65306;<\/p>\n<pre><code class=\"language-bash\">php artisan migrate<\/code><\/pre>\n<h3>2. &#37197;&#32622; Twilio<\/h3>\n<p>&#22312; <code>config\/services.php<\/code> &#25991;&#20214;&#20013;&#28155;&#21152; Twilio &#30340;&#37197;&#32622;&#65306;<\/p>\n<pre><code class=\"language-php\">'twilio' =&gt; [\n    'account_sid' =&gt; env('TWILIO_ACCOUNT_SID'),\n    'auth_token' =&gt; env('TWILIO_AUTH_TOKEN'),\n],<\/code><\/pre>\n<p>&#22312; <code>.env<\/code> &#25991;&#20214;&#20013;&#28155;&#21152; Twilio &#30340;&#36134;&#25143; SID &#21644; Auth Token&#65306;<\/p>\n<pre><code>TWILIO_ACCOUNT_SID=your_account_sid\nTWILIO_AUTH_TOKEN=your_auth_token<\/code><\/pre>\n<h3>3. &#21019;&#24314;&#30701;&#20449;&#36890;&#30693;&#27169;&#22411;<\/h3>\n<p>&#21019;&#24314;&#19968;&#20010;&#26032;&#30340; Eloquent &#27169;&#22411;&#26469;&#34920;&#31034;&#30701;&#20449;&#36890;&#30693;&#65306;<\/p>\n<pre><code class=\"language-bash\">php artisan make:model Notification<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#27169;&#22411;&#20013;&#65292;&#20320;&#21487;&#20197;&#23450;&#20041;&#30701;&#20449;&#30340;&#36890;&#30693;&#20869;&#23481;&#21644;&#25509;&#25910;&#32773;&#20449;&#24687;&#65306;<\/p>\n<pre><code class=\"language-php\">namespace AppModels;\n\nuse IlluminateDatabaseEloquentModel;\n\nclass Notification extends Model\n{\n    protected $fillable = ['content', 'recipient'];\n}<\/code><\/pre>\n<h3>4. &#21019;&#24314;&#30701;&#20449;&#36890;&#30693;&#25511;&#21046;&#22120;<\/h3>\n<p>&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#25511;&#21046;&#22120;&#26469;&#22788;&#29702;&#30701;&#20449;&#36890;&#30693;&#30340;&#25805;&#20316;&#65306;<\/p>\n<pre><code class=\"language-bash\">php artisan make:controller NotificationController<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#25511;&#21046;&#22120;&#20013;&#65292;&#20320;&#21487;&#20197;&#23450;&#20041;&#21019;&#24314;&#12289;&#26356;&#26032;&#21644;&#21024;&#38500;&#30701;&#20449;&#36890;&#30693;&#30340;&#26041;&#27861;&#65306;<\/p>\n<pre><code class=\"language-php\">namespace AppHttpControllers;\n\nuse AppModelsNotification;\nuse IlluminateHttpRequest;\n\nclass NotificationController extends Controller\n{\n    public function store(Request $request)\n    {\n        $notification = new Notification();\n        $notification-&gt;content = $request-&gt;input('content');\n        $notification-&gt;recipient = $request-&gt;input('recipient');\n        $notification-&gt;save();\n\n        return response()-&gt;json(['message' =&gt; 'Notification sent successfully']);\n    }\n\n    public function update(Request $request, $id)\n    {\n        $notification = Notification::findOrFail($id);\n        $notification-&gt;content = $request-&gt;input('content');\n        $notification-&gt;recipient = $request-&gt;input('recipient');\n        $notification-&gt;save();\n\n        return response()-&gt;json(['message' =&gt; 'Notification updated successfully']);\n    }\n\n    public function destroy($id)\n    {\n        $notification = Notification::findOrFail($id);\n        $notification-&gt;delete();\n\n        return response()-&gt;json(['message' =&gt; 'Notification deleted successfully']);\n    }\n}<\/code><\/pre>\n<h3>5. &#21019;&#24314;&#30701;&#20449;&#36890;&#30693;&#36335;&#30001;<\/h3>\n<p>&#22312; <code>routes\/web.php<\/code> &#25991;&#20214;&#20013;&#28155;&#21152;&#30701;&#20449;&#36890;&#30693;&#30340;&#36335;&#30001;&#65306;<\/p>\n<pre><code class=\"language-php\">Route::post('\/notifications', 'NotificationController@store')-&gt;name('notifications.store');\nRoute::put('\/notifications\/{id}', 'NotificationController@update')-&gt;name('notifications.update');\nRoute::delete('\/notifications\/{id}', 'NotificationController@destroy')-&gt;name('notifications.destroy');<\/code><\/pre>\n<h3>6. &#21457;&#36865;&#30701;&#20449;<\/h3>\n<p>&#22312;&#20320;&#30340;&#24212;&#29992;&#31243;&#24207;&#20013;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992; Twilio &#30340; API &#26469;&#21457;&#36865;&#30701;&#20449;&#12290;&#20551;&#35774;&#20320;&#24050;&#32463;&#23433;&#35013;&#20102; Twilio &#30340; Laravel &#39537;&#21160;&#22120;&#65292;&#24182;&#19988;&#37197;&#32622;&#22909;&#20102; Twilio &#30340;&#36134;&#25143; SID &#21644; Auth Token&#65292;&#20320;&#21487;&#20197;&#32534;&#20889;&#19968;&#20010;&#20989;&#25968;&#26469;&#21457;&#36865;&#30701;&#20449;&#65306;<\/p>\n<pre><code class=\"language-php\">use TwilioRestClient;\n\nfunction sendSms($number, $message)\n{\n    $client = new Client(env('TWILIO_ACCOUNT_SID'), env('TWILIO_AUTH_TOKEN'));\n    $message = $client-&gt;messages-&gt;create(\n        $number,\n        array(\n            \"from\" =&gt; \"+1234567890\",\n            \"body\" =&gt; $message\n        )\n    );\n}<\/code><\/pre>\n<h3>7. &#31034;&#20363;&#20195;&#30721;<\/h3>\n<p>&#20197;&#19979;&#26159;&#19968;&#20010;&#23436;&#25972;&#30340;&#31034;&#20363;&#20195;&#30721;&#65292;&#23637;&#31034;&#20102;&#22914;&#20309;&#22312; Laravel &#20013;&#23454;&#29616;&#30701;&#20449;&#36890;&#30693;&#65306;<\/p>\n<h4>1. &#21019;&#24314;&#27169;&#22411;<\/h4>\n<pre><code class=\"language-bash\">php artisan make:model Notification<\/code><\/pre>\n<h4>2. &#37197;&#32622; Twilio<\/h4>\n<p>&#32534;&#36753; <code>config\/services.php<\/code> &#25991;&#20214;&#65306;<\/p>\n<pre><code class=\"language-php\">'twilio' =&gt; [\n    'account_sid' =&gt; env('TWILIO_ACCOUNT_SID'),\n    'auth_token' =&gt; env('TWILIO_AUTH_TOKEN'),\n],<\/code><\/pre>\n<p>&#32534;&#36753; <code>.env<\/code> &#25991;&#20214;&#65306;<\/p>\n<pre><code>TWILIO_ACCOUNT_SID=your_account_sid\nTWILIO_AUTH_TOKEN=your_auth_token<\/code><\/pre>\n<h4>3. &#21019;&#24314;&#25511;&#21046;&#22120;<\/h4>\n<pre><code class=\"language-bash\">php artisan make:controller NotificationController<\/code><\/pre>\n<h4>4. &#21019;&#24314;&#36335;&#30001;<\/h4>\n<pre><code class=\"language-php\">Route::post('\/notifications', 'NotificationController@store')-&gt;name('notifications.store');\nRoute::put('\/notifications\/{id}', 'NotificationController@update')-&gt;name('notifications.update');\nRoute::delete('\/notifications\/{id}', 'NotificationController@destroy')-&gt;name('notifications.destroy');<\/code><\/pre>\n<h4>5. &#21457;&#36865;&#30701;&#20449;<\/h4>\n<pre><code class=\"language-php\">use TwilioRestClient;\n\nfunction sendSms($number, $message)\n{\n    $client = new Client(env('TWILIO_ACCOUNT_SID'), env('TWILIO_AUTH_TOKEN'));\n    $message = $client-&gt;messages-&gt;create(\n        $number,\n        array(\n            \"from\" =&gt; \"+1234567890\",\n            \"body\" =&gt; $message\n        )\n    );\n}<\/code><\/pre>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#20320;&#21487;&#20197;&#22312; Laravel &#20013;&#23454;&#29616;&#30701;&#20449;&#36890;&#30693;&#30340;&#21151;&#33021;&#12290;&#20320;&#21487;&#20197;&#26681;&#25454;&#38656;&#35201;&#36827;&#19968;&#27493;&#25193;&#23637;&#21644;&#20248;&#21270;&#36825;&#20010;&#31995;&#32479;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;Bug&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#40657;&#26495;Bug&#35762;&#24072;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><h2>&#27010;&#35272;<\/h2><p>&#38543;&#30528;&#23454;&#26102;&#36890;&#20449;&#22312;Web&#24212;&#29992;&#20013;&#30340;&#26085;&#30410;&#24517;&#35201;&#24615;&#65292;&#30701;&#20449;&#36890;&#30693;&#25552;&#20379;&#20102;&#19968;&#31181;&#24378;&#22823;&#30340;&#24037;&#20855;&#65292;&#21487;&#20197;&#31435;&#21363;&#19988;&#26377;&#25928;&#22320;&#35302;&#21450;&#29992;&#25143;&#12290;&#22312;&#36825;&#31687;&#25945;&#31243;&#20013;&#65292;&#25105;&#20204;&#23558;&#25506;&#35752;&#22914;&#20309;&#22312;Laravel&#24212;&#29992;&#31243;&#24207;&#20013;&#21457;&#36865;&#30701;&#20449;&#36890;&#30693;&#65292;&#21033;&#29992;Laravel&#20869;&#32622;&#30340;&#36890;&#30693;&#31995;&#32479;&#21644;&#21508;&#31181;&#30701;&#20449;&#26381;&#21153;&#12290;<\/p><h3>&#22312;Laravel&#20013;&#65292;Notification API&#26159;&#19968;&#20010;&#29992;&#20110;&#21457;&#36865;&#36890;&#30693;&#30340;API&#12290;<\/h3><p>Laravel &#25552;&#20379;&#20102;&#38024;&#23545;&#21508;&#31181;&#36890;&#30693;&#28192;&#36947;&#30340;&#24178;&#20928;&#12289;&#31616;&#21333;&#30340; API&#65292;&#21253;&#25324; SMS&#12290;Laravel &#30340;&#25277;&#35937;&#23618;&#20351;&#24471;&#33021;&#22815;&#36731;&#26494;&#20999;&#25442;&#19981;&#21516;&#30340;&#21457;&#36865;&#26381;&#21153;&#65292;&#20363;&#22914; Nexmo&#65288;Vonage&#65289;&#12289;Twilio &#31561;&#12290;<\/p><h3>&#35774;&#32622;&#24744;&#30340;Laravel&#39033;&#30446;<\/h3><p>&#30830;&#20445;&#24744;&#24050;&#20934;&#22791;&#22909;&#21457;&#36865;&#36890;&#30693;&#25152;&#38656;&#30340;&#27169;&#22411;&#65292;&#36890;&#24120;&#26159;&#25351;&#29992;&#25143;&#12290;<\/p><p>&#39318;&#20808;&#65292;&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;Laravel&#39033;&#30446;&#25110;&#23548;&#33322;&#21040;&#29616;&#26377;&#39033;&#30446;&#30340;&#30446;&#24405;&#12290;<\/p><h3>&#37197;&#32622;&#30701;&#20449;&#26381;&#21153;<\/h3><p>&#20320;&#38656;&#35201;&#36873;&#25321;&#19968;&#20010;&#30701;&#20449;&#25552;&#20379;&#21830;&#24182;&#23558;&#20854;&#37197;&#32622;&#21040;&#20320;&#30340;Laravel&#24212;&#29992;&#20013;&#12290;&#22312;&#26412;&#25351;&#21335;&#20013;&#65292;&#25105;&#20204;&#23558;&#20351;&#29992;Nexmo&#20316;&#20026;&#31034;&#20363;&#12290;<\/p><p>&#35831;&#28155;&#21152;&#24744;&#30340;Nexmo&#20973;&#35777;&#21040;&#24744;&#30340;&#31995;&#32479;&#20013;&#12290;<code>.env<\/code>&#25991;&#20214;&#12290;<\/p><p>&#23433;&#35013;Nexmo&#23458;&#25143;&#31471;&#65292;&#35831;&#36816;&#34892;<code>composer require nexmo\/client<\/code>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p><h2>&#21019;&#24314;&#36890;&#30693;<\/h2><p>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#24744;&#38656;&#35201;&#21019;&#24314;&#30340;&#36890;&#30693;&#30340;&#20855;&#20307;&#20449;&#24687;&#25110;&#35201;&#27714;&#65292;&#25105;&#23558;&#20026;&#24744;&#32763;&#35793;&#25104;&#20013;&#25991;&#12290;<code>php artisan make:notification SendSMSNotification<\/code>&#21629;&#20196;&#12290;<\/p><h3>&#35831;&#20351;&#29992;Nexmo&#36890;&#36947;&#12290;<\/h3><p>&#32534;&#36753;&#12290;<code>SendSMSNotification<\/code>&#35201;&#20351;&#29992;Nexmo&#30340;&#30701;&#20449;&#36890;&#36947;&#65292;&#35831;&#21442;&#38405;&#30456;&#20851;&#25351;&#21335;&#12290;<\/p><pre><code>public function via($notifiable)\n{\n    return ['nexmo'];\n}\n\npublic function toNexmo($notifiable)\n{\n    return (new NexmoMessageSMS())\n        -&gt;content('Your notification text here.')\n        -&gt;from('Your_Nexmo_Number');\n}\n<\/code><\/pre><h2>&#27491;&#22312;&#21457;&#36865;&#36890;&#30693;&#12290;<\/h2><p>&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<code>notify<\/code>&#22312;&#24744;&#30340;&#21487;&#36890;&#30693;&#27169;&#22411;&#23454;&#20363;&#19978;&#35774;&#32622;&#26041;&#27861;&#20197;&#21457;&#36865;&#36890;&#30693;&#12290;<\/p><pre><code>use AppNotificationsSendSMSNotification;\n\n$user-&gt;notify(new SendSMSNotification());\n<\/code><\/pre><h2>&#39640;&#32423; &#8211; &#38431;&#21015;&#36890;&#30693;<\/h2><p>&#20026;&#20102;&#38450;&#27490;&#29992;&#25143;&#20307;&#39564;&#20986;&#29616;&#24310;&#35823;&#65292;&#20320;&#24212;&#35813;&#25490;&#38431;&#25512;&#36865;&#36890;&#30693;&#12290;<\/p><pre><code>public function via($notifiable)\n{\n    return ['nexmo', 'database', 'broadcast'];\n}\n<\/code><\/pre><p>&#22312;Laravel&#20013;&#21033;&#29992;&#38431;&#21015;&#21151;&#33021;&#65292;&#21487;&#20197;&#36890;&#36807;&#23454;&#29616;Job Queue&#26469;&#23454;&#29616;&#12290;<code>ShouldQueue<\/code>&#22312;&#20320;&#30340;&#36890;&#30693;&#31867;&#20013;&#23450;&#20041;&#19968;&#20010;&#20869;&#37096;&#25509;&#21475;&#12290;<\/p><pre><code>use IlluminateContractsQueueShouldQueue;\n\nclass SendSMSNotification extends Notification implements ShouldQueue\n{\n    \/\/...\n}\n<\/code><\/pre><h2>&#22788;&#29702;&#36865;&#36135;&#21709;&#24212;&#12290;<\/h2><p>&#35831;&#25552;&#20379;&#38656;&#35201;&#20462;&#25913;&#30340;&#20869;&#23481;&#65292;&#25105;&#20250;&#24110;&#24744;&#36827;&#34892;&#32763;&#35793;&#21644;&#20462;&#25913;&#12290;<code>toNexmo<\/code>&#22788;&#29702;&#20132;&#20184;&#21709;&#24212;&#30340;&#26041;&#27861;&#21450;&#20854;&#26681;&#25454;&#27492;&#21709;&#24212;&#25191;&#34892;&#30456;&#24212;&#25805;&#20316;&#30340;&#31574;&#30053;&#12290;<\/p><pre><code>\/\/...\n\nNexmoMessage(new NexmoMessageSMS())\n    -&gt;send();\n\n\/\/ Handle the response here\n\n\/\/...\n<\/code><\/pre><h2>&#38169;&#35823;&#22788;&#29702;&#21644;&#26085;&#24535;&#35760;&#24405;<\/h2><p>&#22312;&#24744;&#30340;&#36890;&#30693;&#21457;&#36865;&#36923;&#36753;&#20013;&#23454;&#29616;try-catch&#22359;&#20197;&#22788;&#29702;&#20219;&#20309;&#38169;&#35823;&#24182;&#36866;&#24403;&#35760;&#24405;&#23427;&#20204;&#12290;<\/p><pre><code>try {\n    $response = $message-&gt;send();\n} catch (Exception $e) {\n    Log::error($e-&gt;getMessage());\n}\n<\/code><\/pre><h2>&#23450;&#21046;&#36890;&#30693;&#27169;&#22411;<\/h2><p>&#28155;&#21152;&#20102;&#12290;<code>routeNotificationForNexmo<\/code>&#22312;&#24744;&#30340;&#21487;&#36890;&#30693;&#27169;&#22411;&#20013;&#35774;&#32622;&#19968;&#20010;&#26041;&#27861;&#26469;&#33258;&#23450;&#20041;&#36890;&#30693;&#23558;&#34987;&#21457;&#36865;&#21040;&#30340;&#30005;&#35805;&#21495;&#30721;&#12290;<\/p><pre><code>public function routeNotificationForNexmo($notification)\n{\n    return $this-&gt;phone;\n}\n<\/code><\/pre><h2>&#32467;&#35770;&#12290;<\/h2><p>&#32508;&#19978;&#25152;&#36848;&#65292;&#22312;Laravel&#39033;&#30446;&#20013;&#38598;&#25104;&#30701;&#20449;&#36890;&#30693;&#38750;&#24120;&#31616;&#21333;&#65292;&#24471;&#30410;&#20110;Laravel&#30340;&#36890;&#30693;&#31995;&#32479;&#25552;&#20379;&#30340;&#24378;&#22823;&#21151;&#33021;&#12290;&#36890;&#36807;&#21033;&#29992;Laravel&#30340;&#24378;&#22823;&#33021;&#21147;&#21644;&#21508;&#31181;&#30701;&#20449;&#26381;&#21153;&#30340;&#28789;&#27963;&#24615;&#65292;&#24744;&#21487;&#20197;&#20026;&#29992;&#25143;&#25552;&#20379;&#26080;&#32541;&#21644;&#21709;&#24212;&#24335;&#30340;&#20307;&#39564;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--3\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/xygcfznnzczhsdmwydzhsmzzzmddnq-400x300.jpg\" alt=\"&#38271;&#24037;&#30721;&#22900;1523\" class=\"wp-image-2906\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#38271;&#24037;&#30721;&#22900;1523<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>Laravel&#26159;&#19968;&#20010;&#27969;&#34892;&#30340;PHP&#26694;&#26550;&#65292;&#29992;&#20110;&#24555;&#36895;&#26500;&#24314;Web&#24212;&#29992;&#12290;&#20854;&#20013;&#30340;&#19968;&#20010;&#20851;&#38190;&#21151;&#33021;&#26159;&#30701;&#20449;&#36890;&#30693;&#12290;&#19979;&#38754;&#26159;&#19968;&#20123;&#20851;&#20110;&#22914;&#20309;&#20351;&#29992;Laravel&#23454;&#29616;&#30701;&#20449;&#36890;&#30693;&#30340;&#23454;&#29992;&#25351;&#21335;&#12290;<\/p>\n<h3>1. &#23433;&#35013;&#21644;&#35774;&#32622;<\/h3>\n<p>&#39318;&#20808;&#65292;&#30830;&#20445;&#20320;&#30340;&#39033;&#30446;&#24050;&#32463;&#23433;&#35013;&#20102;Composer&#65292;&#24182;&#19988;&#26377;&#27491;&#30830;&#30340;&#20381;&#36182;&#39033;&#12290;&#28982;&#21518;&#36890;&#36807;&#20197;&#19979;&#21629;&#20196;&#23433;&#35013;SwiftMailer&#65306;<\/p>\n<pre><code class=\"language-bash\">composer require swiftmailer\/swiftmailer<\/code><\/pre>\n<p>&#22914;&#26524;&#20320;&#20351;&#29992;&#30340;&#26159;VSCode&#65292;&#35831;&#30830;&#20445;&#24050;&#21551;&#29992;SwiftMailer&#25554;&#20214;&#12290;<\/p>\n<h3>2. &#37197;&#32622;SwiftMailer<\/h3>\n<p>&#22312;<code>config\/mail.php<\/code>&#25991;&#20214;&#20013;&#37197;&#32622;SwiftMailer&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\nreturn [\n    'swiftmailer' =&gt; [\n        'class' =&gt; 'Swift_Mailer',\n        'path' =&gt; __DIR__.'\/..\/vendor\/bin\/swift_mailer',\n        \/\/ &#26356;&#22810;&#37197;&#32622;&#36873;&#39033;...\n    ],\n];<\/code><\/pre>\n<h3>3. &#21457;&#36865;&#30701;&#20449;&#36890;&#30693;<\/h3>\n<p>&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#25511;&#21046;&#22120;&#26469;&#22788;&#29702;&#30701;&#20449;&#36890;&#30693;&#35831;&#27714;&#12290;&#20363;&#22914;&#65292;&#25105;&#20204;&#21487;&#20197;&#21019;&#24314;&#19968;&#20010;&#21517;&#20026;<code>SendSmsNotificationController<\/code>&#30340;&#25511;&#21046;&#22120;&#65306;<\/p>\n<pre><code class=\"language-php\">use AppNotificationsSmsNotification;\nuse IlluminateSupportFacadesMail;\n\npublic function sendSMS($message, $to)\n{\n    Mail::send(new SmsNotification($message, $to));\n}<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#25511;&#21046;&#22120;&#20013;&#65292;&#25105;&#20204;&#23450;&#20041;&#20102;&#19968;&#20010;&#26041;&#27861;<code>sendSMS<\/code>&#65292;&#23427;&#25509;&#21463;&#20004;&#20010;&#21442;&#25968;&#65306;&#28040;&#24687;&#65288;$message&#65289;&#21644;&#25509;&#25910;&#32773;&#30005;&#35805;&#21495;&#30721;&#65288;$to&#65289;&#12290;&#28982;&#21518;&#65292;&#25105;&#20204;&#20351;&#29992;SwiftMailer&#21457;&#36865;&#30701;&#20449;&#36890;&#30693;&#12290;<\/p>\n<h3>4. &#20351;&#29992;SwiftMailer&#21457;&#36865;&#30701;&#20449;&#36890;&#30693;<\/h3>\n<p>&#20551;&#35774;&#25105;&#20204;&#26377;&#19968;&#20010;&#29992;&#25143;&#34920;&#65292;&#20854;&#20013;&#26377;&#19968;&#20010;&#23383;&#27573;<code>phone_number<\/code>&#23384;&#20648;&#29992;&#25143;&#30340;&#25163;&#26426;&#21495;&#30721;&#12290;&#29616;&#22312;&#25105;&#20204;&#35201;&#21457;&#36865;&#30701;&#20449;&#36890;&#30693;&#32473;&#29305;&#23450;&#29992;&#25143;&#12290;&#21487;&#20197;&#36825;&#26679;&#25805;&#20316;&#65306;<\/p>\n<pre><code class=\"language-php\">\/\/ &#20551;&#35774;&#25105;&#20204;&#30340;&#29992;&#25143;&#27169;&#22411;&#22914;&#19979;&#65306;\nUser::create([\n    'name' =&gt; 'John Doe',\n    'phone_number' =&gt; '+1234567890'\n]);\n\n$user = User::find(1); \/\/ &#33719;&#21462;&#29992;&#25143;ID&#20026;1&#30340;&#29992;&#25143;&#23454;&#20363;\n\n\/\/ &#21019;&#24314;&#24182;&#21457;&#36865;&#30701;&#20449;&#36890;&#30693;\n$notification = new SendSmsNotification();\n$notification-&gt;message = \"Hello, this is a test message!\";\n$notification-&gt;recipient = $user-&gt;phone_number;\n\n$notification-&gt;save();\n\nMail::send('emails.send-sms', $notification, function ($m) use ($user) {\n    $m-&gt;from('&lt;your-email@example.com&gt;', '&lt;Your Name&gt;');\n    $m-&gt;to($user-&gt;email)-&gt;subject('Test SMS Notification');\n});<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;&#25105;&#20204;&#39318;&#20808;&#20174;&#25968;&#25454;&#24211;&#33719;&#21462;&#29992;&#25143;&#23454;&#20363;&#65292;&#28982;&#21518;&#21019;&#24314;&#24182;&#20445;&#23384;&#19968;&#26465;&#26032;&#30340;&#30701;&#20449;&#36890;&#30693;&#23545;&#35937;&#12290;&#26368;&#21518;&#65292;&#25105;&#20204;&#20351;&#29992;SwiftMailer&#21457;&#36865;&#30701;&#20449;&#36890;&#30693;&#12290;<\/p>\n<h3>5. &#26816;&#26597;&#30701;&#20449;&#36890;&#30693;&#26159;&#21542;&#25104;&#21151;&#21457;&#36865;<\/h3>\n<p>&#35201;&#26816;&#26597;&#30701;&#20449;&#36890;&#30693;&#26159;&#21542;&#25104;&#21151;&#21457;&#36865;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;<code>Mail::hasFailed()<\/code>&#20989;&#25968;&#12290;&#36825;&#23558;&#36820;&#22238;&#19968;&#20010;&#24067;&#23572;&#20540;&#65292;&#25351;&#31034;&#26159;&#21542;&#26377;&#20219;&#20309;&#22833;&#36133;&#30340;&#37038;&#20214;&#34987;&#21457;&#36865;&#12290;<\/p>\n<pre><code class=\"language-php\">$failedEmails = Mail::hasFailed();\n\nif (!$failedEmails) {\n    echo \"All SMS notifications were sent successfully.\";\n} else {\n    echo \"Some SMS notifications failed to be sent.\";\n}<\/code><\/pre>\n<h3>&#24635;&#32467;<\/h3>\n<p>&#20197;&#19978;&#23601;&#26159;&#20351;&#29992;Laravel&#21457;&#36865;&#30701;&#20449;&#36890;&#30693;&#30340;&#22522;&#26412;&#27493;&#39588;&#12290;&#35760;&#20303;&#65292;&#20026;&#20102;&#23433;&#20840;&#36215;&#35265;&#65292;&#20320;&#24212;&#35813;&#32771;&#34385;&#23545;&#23494;&#30721;&#36827;&#34892;&#21152;&#23494;&#65292;&#20197;&#38450;&#20449;&#24687;&#34987;&#30423;&#21462;&#12290;&#21516;&#26102;&#65292;&#20320;&#20063;&#24212;&#35813;&#23450;&#26399;&#22791;&#20221;&#25968;&#25454;&#65292;&#20197;&#38450;&#25968;&#25454;&#20002;&#22833;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#26631;&#39064;&#65306;Laravel&#20013;&#30340;&#30701;&#20449;&#36890;&#30693;&#65306;&#23454;&#29992;&#25351;&#21335; &#27491;&#038;#25..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[44],"tuisongtax":[],"class_list":["post-860","my1js","type-my1js","status-publish","hentry","my1js2nav-laravel"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/860","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=860"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=860"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=860"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}