<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
  <channel>
    <title>Laravel｜林鼎淵 Dean Lin</title>
    <link>https://deanlin.net/tags/laravel/</link>
    <image><url>https://deanlin.net/images/author_hu_aa256fc934e9a932.jpg</url><title>Laravel｜林鼎淵 Dean Lin</title><link>https://deanlin.net/tags/laravel/</link><width>144</width><height>144</height></image>
    <description>林鼎淵（Dean Lin）的部落格：生成式 AI 企業內訓講師、外商資安公司軟體專家、7 本書作者。400 多篇文章用白話分享生成式 AI 實戰、Claude Code 與 Vibe Coding 教學、團隊合作與職場成長。</description>
    <generator>Hugo</generator>
    <language>zh-tw</language>
    <copyright>© 2020–2026 林鼎淵 Dean Lin</copyright>
    <lastBuildDate>Wed, 17 Jun 2020 17:01:07 +0800</lastBuildDate>
    <atom:link href="https://deanlin.net/tags/laravel/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Laravel經驗</title>
      <link>https://deanlin.net/blog/202006/laravel-experience-notes/</link>
      <pubDate>Wed, 17 Jun 2020 17:01:07 +0800</pubDate>
      <guid>https://deanlin.net/blog/202006/laravel-experience-notes/</guid>
      <dc:creator>林鼎淵</dc:creator>
      <category>技術教學</category>
      <description>希望這篇文章可以幫助你快速通過我在開發Laravel時所遇到的各種坑(如果有遇到新的我會持續更新)</description>
      <media:content url="https://deanlin.net/blog/202006/laravel-experience-notes/images/laravel-experience-notes-og_hu_c471f62bca98d1ce.jpg" medium="image" type="image/jpeg" width="1200" height="675" />
      <content:encoded><![CDATA[<p><img src="https://deanlin.net/blog/202006/laravel-experience-notes/images/laravel-experience-notes-01.webp" width="500" height="320" alt="Laravel經驗（圖 1）" fetchpriority="high" decoding="async"></p>
<h3 id="為什麼總是要-composer-dump-autoload-">為什麼總是要 composer dump-autoload ?<a class="h-anchor" href="#%e7%82%ba%e4%bb%80%e9%ba%bc%e7%b8%bd%e6%98%af%e8%a6%81-composer-dump-autoload-" aria-label="這個段落的連結"></a></h3>
<p>剛開始接觸用 composer 的時候一直被這個問題蠱惑。很不理解為什麼總是要打這句命令才能不報錯，現在終於知道根結了。</p>
<p>因為 database 文件夾使用 classmap 來做加載的。所以只有在打了 composer dumpautoload 之後 composer 才會更新 autoload_classmap 的內容。</p>
<h3 id="遇到無法composer可用這個">遇到無法composer可用這個<a class="h-anchor" href="#%e9%81%87%e5%88%b0%e7%84%a1%e6%b3%95composer%e5%8f%af%e7%94%a8%e9%80%99%e5%80%8b" aria-label="這個段落的連結"></a></h3>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo apt-get install php-mbstring
</span></span><span style="display:flex;"><span>sudo apt-get install php-xml
</span></span></code></pre></div><h3 id="如果遇到log讀寫權限不足">如果遇到log讀寫權限不足<a class="h-anchor" href="#%e5%a6%82%e6%9e%9c%e9%81%87%e5%88%b0log%e8%ae%80%e5%af%ab%e6%ac%8a%e9%99%90%e4%b8%8d%e8%b6%b3" aria-label="這個段落的連結"></a></h3>
<pre tabindex="0"><code>vim /etc/nginx/nginx.conf
</code></pre><p>去看nginx的權限user www-data;</p>
<p>Laravel的資料夾權限需要跟nginx一樣</p>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>chown -R www-data.www-data device-api
</span></span><span style="display:flex;"><span>sudo chgrp -R www-data storage bootstrap/cache
</span></span><span style="display:flex;"><span>sudo chmod -R ug+rwx storage bootstrap/cache
</span></span></code></pre></div><h3 id="php-fpm錯誤-warning-pool-www-server-reached-pmmax_children-setting-5-consider-raising-it">php-fpm錯誤: WARNING: [pool www] server reached pm.max_children setting (5), consider raising it<a class="h-anchor" href="#php-fpm%e9%8c%af%e8%aa%a4-warning-pool-www-server-reached-pmmax_children-setting-5-consider-raising-it" aria-label="這個段落的連結"></a></h3>
<p><a href="https://blog.csdn.net/encircles/article/details/80503756">https://blog.csdn.net/encircles/article/details/80503756</a></p>
<h3 id="timeout相關包含nginx-php-fpm">timeout相關(包含nginx, php-fpm)<a class="h-anchor" href="#timeout%e7%9b%b8%e9%97%9c%e5%8c%85%e5%90%abnginx-php-fpm" aria-label="這個段落的連結"></a></h3>
<p><a href="https://blog.goodjack.tw/2018/08/increase-php-fpm-script-execution-time-with-nginx.html">https://blog.goodjack.tw/2018/08/increase-php-fpm-script-execution-time-with-nginx.html</a></p>
<h3 id="composer-版本太舊無法更新問題">composer 版本太舊無法更新問題<a class="h-anchor" href="#composer-%e7%89%88%e6%9c%ac%e5%a4%aa%e8%88%8a%e7%84%a1%e6%b3%95%e6%9b%b4%e6%96%b0%e5%95%8f%e9%a1%8c" aria-label="這個段落的連結"></a></h3>
<p>https://lequ7.com/2019/06/19/richang/composer-fu-wu-qi-an-zhuang-kuo-zhan-shi-bai-ban-ben-guo-di-de-sheng-ji-guo-cheng/</p>
<h3 id="nginx-出现504-gateway-time-out的解决方法">nginx 出现504 Gateway Time-out的解决方法<a class="h-anchor" href="#nginx-%e5%87%ba%e7%8e%b0504-gateway-time-out%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95" aria-label="這個段落的連結"></a></h3>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo vi /etc/nginx/nginx.conf
</span></span></code></pre></div><p>系統有超過 300~500mb的影片，这了，超時時<a href="https://blog.csdn.net/fdipzone/article/details/79355576">間調整為30分鐘；這裡有更詳細的說明</a></p>
<pre tabindex="0"><code>proxy_connect_timeout 1800s;#nginx跟後端服務器連接超時時間(代理連接超時)
proxy_send_timeout 1800s;#後端服務器數據回傳時間(代理發送超時)
proxy_read_timeout 1800s;#連接成功後，後端服務器響應時間(代理接收超時)
fastcgi_connect_timeout 1800s;#指定nginx與後端fastcgi server連接超時時間
fastcgi_send_timeout 1800s;#指定nginx向後端傳送請求超時時間（指已完成兩次握手後向fastcgi傳送請求超時時間）
fastcgi_read_timeout 1800s;#指定nginx向後端傳送響應超時時間（指已完成兩次握手後向fastcgi傳送請求超時時間）
</code></pre><h3 id="laravel-同時間大量update會有數據對不上的問題transaction-issue">Laravel 同時間大量update會有數據對不上的問題(transaction issue)<a class="h-anchor" href="#laravel-%e5%90%8c%e6%99%82%e9%96%93%e5%a4%a7%e9%87%8fupdate%e6%9c%83%e6%9c%89%e6%95%b8%e6%93%9a%e5%b0%8d%e4%b8%8d%e4%b8%8a%e7%9a%84%e5%95%8f%e9%a1%8ctransaction-issue" aria-label="這個段落的連結"></a></h3>
<p><a href="https://blog.scottchayaa.com/post/2019/01/09/how-to-handle-the-high-concurrency-on-laravel/">https://blog.scottchayaa.com/post/2019/01/09/how-to-handle-the-high-concurrency-on-laravel/</a></p>
<h3 id="php的mysql沒有安裝完整的錯誤">Php的mysql沒有安裝完整的錯誤<a class="h-anchor" href="#php%e7%9a%84mysql%e6%b2%92%e6%9c%89%e5%ae%89%e8%a3%9d%e5%ae%8c%e6%95%b4%e7%9a%84%e9%8c%af%e8%aa%a4" aria-label="這個段落的連結"></a></h3>
<p>PHP Warning: PHP Startup: Unable to load dynamic library ‘pdo_mysql’ (tried: /usr/lib/php/20170718/pdo_mysql (/usr/lib/php/20170718/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/pdo_mysql.so (/usr/lib/php/20170718/pdo_mysql.so: undefined symbol: pdo_parse_params)) in Unknown on line 0</p>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo apt-get install php-common php-mysql php-cli
</span></span></code></pre></div><h3 id="如果出現php版本跑掉的狀況不要擔心">如果出現php版本跑掉的狀況，不要擔心<a class="h-anchor" href="#%e5%a6%82%e6%9e%9c%e5%87%ba%e7%8f%bephp%e7%89%88%e6%9c%ac%e8%b7%91%e6%8e%89%e7%9a%84%e7%8b%80%e6%b3%81%e4%b8%8d%e8%a6%81%e6%93%94%e5%bf%83" aria-label="這個段落的連結"></a></h3>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo update-alternatives — config php
</span></span></code></pre></div><h3 id="確認現在php支援databsae的相容性">確認現在php支援databsae的相容性<a class="h-anchor" href="#%e7%a2%ba%e8%aa%8d%e7%8f%be%e5%9c%a8php%e6%94%af%e6%8f%b4databsae%e7%9a%84%e7%9b%b8%e5%ae%b9%e6%80%a7" aria-label="這個段落的連結"></a></h3>
<p>php artisan tinker</p>
<p>DB::availableDrivers()</p>
<h3 id="只想要讓某個-function-可以執行長時間的任務ex上傳檔案">只想要讓某個 function 可以執行長時間的任務（ex：上傳檔案）<a class="h-anchor" href="#%e5%8f%aa%e6%83%b3%e8%a6%81%e8%ae%93%e6%9f%90%e5%80%8b-function-%e5%8f%af%e4%bb%a5%e5%9f%b7%e8%a1%8c%e9%95%b7%e6%99%82%e9%96%93%e7%9a%84%e4%bb%bb%e5%8b%99ex%e4%b8%8a%e5%82%b3%e6%aa%94%e6%a1%88" aria-label="這個段落的連結"></a></h3>
<p>在 function 裡面加上 <code>ini_set(&lsquo;mac_excution_time&rsquo;,&lsquo;600&rsquo;)</code> ，其中「600」的單位是秒數。</p>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-php" data-lang="php"><span style="display:flex;"><span><span style="color:#ff7b72">public</span> <span style="color:#ff7b72">function</span> <span style="color:#d2a8ff;font-weight:bold">long_excution_function</span>(Request <span style="color:#79c0ff">$request</span>) {
</span></span><span style="display:flex;"><span>  ini_set(<span style="color:#a5d6ff">&#39;max_execution_time&#39;</span>, <span style="color:#a5d6ff">&#39;600&#39;</span>);
</span></span><span style="display:flex;"><span>  <span style="color:#8b949e;font-style:italic">// your code
</span></span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p class="code-source">原始碼：<a href="https://gist.github.com/dean9703111/966cd5c90443b8d5a2308df9968d5cf8" rel="noopener">long_excution_function.php</a>（GitHub Gist）</p>
]]></content:encoded>
    </item>
    <item>
      <title>Laravel常用指令</title>
      <link>https://deanlin.net/blog/202006/laravel-common-commands/</link>
      <pubDate>Tue, 16 Jun 2020 17:05:47 +0800</pubDate>
      <guid>https://deanlin.net/blog/202006/laravel-common-commands/</guid>
      <dc:creator>林鼎淵</dc:creator>
      <category>技術教學</category>
      <description>laravel有很多常用的指令，但有時候會忘記或是不想自己全部打完，那這篇文章就是你專門用來複製貼上的大補帖</description>
      <media:content url="https://deanlin.net/blog/202006/laravel-common-commands/images/laravel-common-commands-og_hu_9496b00eff300207.jpg" medium="image" type="image/jpeg" width="1200" height="675" />
      <content:encoded><![CDATA[<p><img src="https://deanlin.net/blog/202006/laravel-common-commands/images/laravel-common-commands-01.webp" width="1400" height="583" alt="Laravel常用指令（圖 1）" fetchpriority="high" decoding="async"></p>
<blockquote>
<p>這篇文章會列出我在使用Laraval框架時常用到的指令(部分是套件指令)</p>
</blockquote>
<h2 class="h-nomark" id="1-資料庫相關指令">1. 資料庫相關指令<a class="h-anchor" href="#1-%e8%b3%87%e6%96%99%e5%ba%ab%e7%9b%b8%e9%97%9c%e6%8c%87%e4%bb%a4" aria-label="這個段落的連結"></a></h2>
<p><strong>Migration 資料庫完全重新設定</strong></p>
<pre tabindex="0"><code>php artisan migrate:refresh — seed
</code></pre><p><strong>備份應用程式包括資料庫，<a href="https://codertw.com/%E7%A8%8B%E5%BC%8F%E8%AA%9E%E8%A8%80/190804/">請確認是否已經安裝plugin</a></strong></p>
<pre tabindex="0"><code>php artisan backup:run
</code></pre><p><strong>備份的資料庫執行</strong></p>
<pre tabindex="0"><code>php artisan backup:run --only-db
</code></pre><p><strong>只需要備份的檔案</strong></p>
<pre tabindex="0"><code>php artisan backup:run --only-files
</code></pre><p><strong>database 還原</strong></p>
<pre tabindex="0"><code>mysql -u root -p database_name &lt; backup.sql
</code></pre><h2 class="h-nomark" id="2-安裝檔遺失相關issue">2. 安裝檔遺失相關issue<a class="h-anchor" href="#2-%e5%ae%89%e8%a3%9d%e6%aa%94%e9%81%ba%e5%a4%b1%e7%9b%b8%e9%97%9cissue" aria-label="這個段落的連結"></a></h2>
<p><strong>composer 全部砍掉重裝</strong></p>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>rm -rf vendor/
</span></span><span style="display:flex;"><span>composer update -v
</span></span></code></pre></div><h2 class="h-nomark" id="3-laravel-常用指令">3. Laravel 常用指令<a class="h-anchor" href="#3-laravel-%e5%b8%b8%e7%94%a8%e6%8c%87%e4%bb%a4" aria-label="這個段落的連結"></a></h2>
<p><strong>創建model</strong></p>
<pre tabindex="0"><code>php artisan make:model Photo
</code></pre><p><strong>創建controller</strong></p>
<pre tabindex="0"><code>php artisan make:controller UserController
</code></pre><p><strong>創建migration</strong></p>
<pre tabindex="0"><code>php artisan make:migration create_users_table — table=users
</code></pre><p><strong>創建seeder</strong></p>
<pre tabindex="0"><code>php artisan make:seeder UsersTableSeeder
</code></pre><p><strong>創建middleware</strong></p>
<pre tabindex="0"><code>php artisan make:middleware CheckAge
</code></pre><p><strong>創建job</strong></p>
<pre tabindex="0"><code>php artisan make:job SendReminderEmail
</code></pre><p><strong>創建testcase</strong></p>
<pre tabindex="0"><code>php artisan make:test UserTest
</code></pre><h2 class="h-nomark" id="4-php相關指令">4. php相關指令<a class="h-anchor" href="#4-php%e7%9b%b8%e9%97%9c%e6%8c%87%e4%bb%a4" aria-label="這個段落的連結"></a></h2>
<p><strong>尋找php.ini</strong></p>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>sudo find / -name ‘php.ini’
</span></span></code></pre></div><p><strong>更改php相關設定(如果遇到nginx 502也能用這個重啟嘗試看看)</strong></p>
<pre tabindex="0"><code>vi /etc/php/7.3/fpm/php.ini
service php7.3-fpm restart
</code></pre><h2 class="h-nomark" id="5-單元測試">5. 單元測試<a class="h-anchor" href="#5-%e5%96%ae%e5%85%83%e6%b8%ac%e8%a9%a6" aria-label="這個段落的連結"></a></h2>
<pre tabindex="0"><code>./vendor/bin/phpunit
// 如果使用sudo權限來做測試，部分storage會變成admin權限，這個指令可以讓整個資料夾回歸www-data權限
chown -R www-data:www-data storage/
</code></pre><h2 class="h-nomark" id="6-排程相關">6. 排程相關<a class="h-anchor" href="#6-%e6%8e%92%e7%a8%8b%e7%9b%b8%e9%97%9c" aria-label="這個段落的連結"></a></h2>
<p><strong>排程重啟supervisor</strong></p>
<div class="highlight"><pre tabindex="0" style="color:#e6edf3;background-color:#0d1117;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>// 檔案位置
</span></span><span style="display:flex;"><span>/etc/supervisor/conf.d
</span></span><span style="display:flex;"><span>// 每次修改需要執行這幾個指令重啟<span style="color:#ff7b72;font-weight:bold">(</span>開啟<span style="color:#ff7b72;font-weight:bold">)</span>
</span></span><span style="display:flex;"><span>sudo supervisorctl reread
</span></span><span style="display:flex;"><span>sudo supervisorctl update
</span></span><span style="display:flex;"><span>sudo supervisorctl start laravel-worker:*
</span></span><span style="display:flex;"><span>sudo supervisorctl restart laravel-worker:*
</span></span></code></pre></div><p><strong>本機local端測試排程job</strong></p>
<p>下面幾種job為我個人將每個排程進行分類，讓需要較長時間的排程不會影響到其他短時間能完成的排程</p>
<pre tabindex="0"><code>php artisan queue:work — queue=small_job,default — timeout=600 — delay=3 — sleep=3 — tries=3
php artisan queue:work — queue=big_job,default — timeout=7200 — delay=3 — sleep=3 — tries=3
php artisan queue:work — queue=default — delay=3 — sleep=3 — tries=3
</code></pre><h2 class="h-nomark" id="7-查看錯誤訊息">7. 查看錯誤訊息<a class="h-anchor" href="#7-%e6%9f%a5%e7%9c%8b%e9%8c%af%e8%aa%a4%e8%a8%8a%e6%81%af" aria-label="這個段落的連結"></a></h2>
<p>如果為 php 的錯誤訊息</p>
<pre tabindex="0"><code>vi /var/log/php7.3-fpm.log
</code></pre><p>如果為 Laravel 的錯誤訊息</p>
<pre tabindex="0"><code>vi project_path/storage/logs/laravel-xxx-xx.log
</code></pre><blockquote>
<p>從 log 就能推斷出大部分的問題，並取得查詢的關鍵字</p>
</blockquote>
]]></content:encoded>
    </item>
  </channel>
</rss>
