<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Natthanon O. on Medium]]></title>
        <description><![CDATA[Stories by Natthanon O. on Medium]]></description>
        <link>https://medium.com/@vetosers?source=rss-7edbc90e6252------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gIkw7XGvfBhJD4eEcNSqNw.jpeg</url>
            <title>Stories by Natthanon O. on Medium</title>
            <link>https://medium.com/@vetosers?source=rss-7edbc90e6252------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 01:01:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vetosers/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[การปรับใช้ Laravel Framework บน Share Hosting ที่ง่ายยิ่งกว่าปอกกล้วยเข้าปาก !!]]></title>
            <link>https://medium.com/@vetosers/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%9B%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B9%83%E0%B8%8A%E0%B9%89-laravel-framework-%E0%B8%9A%E0%B8%99-share-hosting-%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2%E0%B8%A2%E0%B8%B4%E0%B9%88%E0%B8%87%E0%B8%81%E0%B8%A7%E0%B9%88%E0%B8%B2%E0%B8%9B%E0%B8%AD%E0%B8%81%E0%B8%81%E0%B8%A5%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B9%80%E0%B8%82%E0%B9%89%E0%B8%B2%E0%B8%9B%E0%B8%B2%E0%B8%81-85d17444795d?source=rss-7edbc90e6252------2</link>
            <guid isPermaLink="false">https://medium.com/p/85d17444795d</guid>
            <dc:creator><![CDATA[Natthanon O.]]></dc:creator>
            <pubDate>Sun, 07 Jan 2018 09:21:56 GMT</pubDate>
            <atom:updated>2018-01-07T09:21:56.613Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*aCCH418GrsTqzVdEONe33g.png" /></figure><p>ตามคอนเซ็ปต์ของผมที่จะไม่ให้บทความยาวเกินไปและดูน่าเบื่อ เรามาเริ่มกันเลย</p><p>หลังจากสร้างโปรเจคหรือทำอะไรเสร็จเรียบร้อยแล้วเราจะอัพไฟล์ทั้งหมดไปไว้ใน Share Hosting ซึ่งวิธีการก็จะเป็นประมาณนี้ โดยกรณีนี้โปรเจคผมจะสมมุติให้ชื่อว่า LaravelShareHost โดยโดเมนที่จะให้ใช้กับโปรเจคนี้คือ https://laravelsharehost.com/</p><ol><li>สร้างโฟลเดอร์ LaravelShareHost ใน public_html หลังจากนั้นอัพไฟล์ทั้งหมดจากโปรเจคเข้าไปไว้ใน LaravelShareHost</li><li>สร้างไฟล์ .htaccess ไว้ใน public_html โดยข้อมูลภายในจะเป็นดังต่อไปนี้</li></ol><pre>RewriteEngine on<br>RewriteCond %{HTTP_HOST} ^(<a href="http://www.)/?tomatoeazyshop.com$">www.)?</a>laravelsharehost<a href="http://www.)/?tomatoeazyshop.com$">.com$</a><br>RewriteCond %{REQUEST_URI} !^/LaravelShareHost/public/<br>RewriteCond %{REQUEST_FILENAME} !-f<br>RewriteCond %{REQUEST_FILENAME} !-d<br>RewriteRule ^(.*)$ /LaravelShareHost/public/$1<br>RewriteCond %{HTTP_HOST} ^(<a href="http://www.)/?tomatoeazyshop.com$">www.)?</a>laravelsharehost<a href="http://www.)/?tomatoeazyshop.com$">.com$</a><br>RewriteRule ^(/)?$ LaravelShareHost/public/index.php [L]</pre><p>แค่เท่านี้ล่ะครับเรียบร้อยแล้ว ซึ่งการนำมาปรับใช้ก็มีด้วยกันหลายวิธีซึ่งผมเลือกใช้วิธีนี้เนื่องจากง่ายและไม่เสียเวลา</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85d17444795d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[เบื่อไหมกับ where() และ orWhere() ที่มีมหาศาลเมื่อใช้งาน Eloquent]]></title>
            <link>https://medium.com/@vetosers/%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B9%84%E0%B8%AB%E0%B8%A1%E0%B8%81%E0%B8%B1%E0%B8%9A-where-%E0%B9%81%E0%B8%A5%E0%B8%B0-orwhere-%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B8%A1%E0%B8%B5%E0%B8%A1%E0%B8%AB%E0%B8%B2%E0%B8%A8%E0%B8%B2%E0%B8%A5%E0%B9%80%E0%B8%A1%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-eloquent-1f7fd7c6da88?source=rss-7edbc90e6252------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f7fd7c6da88</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[eloquent]]></category>
            <dc:creator><![CDATA[Natthanon O.]]></dc:creator>
            <pubDate>Tue, 28 Nov 2017 13:43:13 GMT</pubDate>
            <atom:updated>2017-11-28T13:54:34.549Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*aCCH418GrsTqzVdEONe33g.png" /></figure><p>สร้าง Trait ไว้ที่ app\Traits โดยที่ผมสร้างคือ SearchableTrait.php และมีรายละเอียดดังนี้</p><pre><strong>&lt;?php<br><br>namespace </strong>App\Traits;<br><br><strong>use </strong>Illuminate\Database\Eloquent\Builder;<br><strong>use </strong>Illuminate\Support\Facades\Schema;<br><br><strong>trait </strong>SearchableTrait {<br><br>    <em>/**<br>     * Scope a query to searchable.<br>     *<br>     * </em><strong><em>@param </em></strong><em>\Illuminate\Database\Eloquent\Builder $builder<br>     * </em><strong><em>@param </em></strong><em>string $keyword<br>     * </em><strong><em>@param </em></strong><em>null|string|array $filters<br>     * </em><strong><em>@return </em></strong><em>\Illuminate\Database\Eloquent\Builder<br>     */<br>    </em><strong>public function </strong>scopeSearch(Builder $builder, $keyword, $filters = <strong>null</strong>)<br>    {<br>        $fields = <strong>array</strong>();<br>        <strong>switch </strong>($filters) {<br>            <strong>case null</strong>:<br>                $fields = $this-&gt;fillable;<br>                <strong>break</strong>;<br>            <strong>case </strong>is_string($filters):<br>                <strong>if </strong>($filters == &#39;*&#39;) {<br>                    $fields = Schema::<em>getColumnListing</em>($this-&gt;table);<br>                } <strong>else </strong>{<br>                    array_push($fields, $filters);<br>                }<br>                <strong>break</strong>;<br>            <strong>case </strong>is_array($filters):<br>                $fields = $filters;<br>                <strong>break</strong>;<br>            <strong>default</strong>:<br>                $fields = $this-&gt;fillable;<br>        }<br>        <strong>if </strong>(!<strong>empty</strong>($keyword) || !is_null($keyword)) {<br>            $builder-&gt;where(<strong>function </strong>($builder) <strong>use </strong>($keyword, $fields) {<br>                <strong>foreach </strong>($fields <strong>as </strong>$key =&gt; $field) {<br>                    <strong>if </strong>($key == 0) {<br>                        $builder-&gt;where($field, &quot;LIKE&quot;,&quot;%$keyword%&quot;);<br>                    } <strong>else </strong>{<br>                        $builder-&gt;orWhere($field, &quot;LIKE&quot;, &quot;%$keyword%&quot;);<br>                    }<br>                }<br>            });<br>        }<br>        <strong>return </strong>$builder;<br>    }<br>    <br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X05LU46KFzvyCPUTzaicqQ.jpeg" /><figcaption><a href="https://www.youtube.com/watch?v=cDpgNUq4KBs">PHP overview: Understanding traits | lynda.com — YouTube</a></figcaption></figure><p>ต่อไปเป็นส่วนของการใช้งานเมื่อต้องการใช้งาน ยกตัวอย่างจาก model User</p><pre><strong>&lt;?php<br><br>namespace </strong>App;</pre><pre><strong>use </strong>App\Traits\SearchableTrait <strong>as </strong>Searchable;<br><strong>use </strong>Illuminate\Notifications\Notifiable;<br><strong>use </strong>Illuminate\Foundation\Auth\User <strong>as </strong>Authenticatable;<br><br><strong>class </strong>User <strong>extends </strong>Authenticatable<br>{<br>    <strong>use </strong>Searchable, Notifiable;<br><br>    <em>/**<br>     * The attributes that are mass assignable.<br>     *<br>     * </em><strong><em>@var </em></strong><em>array<br>     */<br>    </em><strong>protected </strong>$fillable = [<br>        &#39;name&#39;, &#39;email&#39;, &#39;password&#39;,<br>    ];<br><br>    <em>/**<br>     * The attributes that should be hidden for arrays.<br>     *<br>     * </em><strong><em>@var </em></strong><em>array<br>     */<br>    </em><strong>protected </strong>$hidden = [<br>        &#39;password&#39;, &#39;remember_token&#39;,<br>    ];<br>}</pre><p>สังเกตุส่วนที่ผมเพิ่มไปคือ <strong>use</strong> App\Traits\SearchableTrait <strong>as</strong> Searchable; และ <strong>use</strong> Searchable; เมื่อต้องการใช้งานฟังก์ชั่นค้นหาก็สามารถใช้งานได้ดังต่อไปนี้</p><pre><em>/**<br> * Display a listing of the resource.<br> *<br> * </em><strong><em>@param </em></strong><em>Request $request<br> * </em><strong><em>@return </em></strong><em>\Illuminate\Http\Response<br> */<br></em><strong>public function </strong>index(Request $request)<br>{<br>    <strong>if </strong>($request-&gt;has(&#39;search&#39;) &amp;&amp; $request-&gt;get(&#39;search&#39;) == &#39;&#39;) {<br>        <strong>return </strong>redirect()-&gt;route(&#39;index&#39;);<br>    } <strong>else </strong>{<br>        <strong>if </strong>(!<strong>empty</strong>($request-&gt;get(&#39;search&#39;))) {<br>            $models = SalesOrder::<em>query</em>()-&gt;search($request-&gt;get(&#39;search&#39;))-&gt;get();<br>        } <strong>else </strong>{<br>            $models = SalesOrder::<em>withTrashed</em>()-&gt;get();<br>        }<br>    }<br><br>    <strong>return </strong>view(&#39;index&#39;)-&gt;with(compact(&#39;models&#39;));<br>}</pre><p>ซึ่งจากโค้ดตัวอย่างผมได้กำหนดค่า parameters ให้สามารถทำงานที่มีความต้องการเพิ่มขึ้นมาอีกหน่อยได้ดังนี้</p><pre>// ค้นหาจากฟิลด์ที่กำหนดไว้ใน $fillable<br>-&gt;search(&#39;Keyword&#39;)-&gt;get();</pre><pre>// ค้นหาจากทุกฟิลด์ใน Table<br>-&gt;search(&#39;Keyword&#39;, &#39;*&#39;)-&gt;get();</pre><pre>// ค้นหาจากฟิลด์ name<br>-&gt;search(&#39;Keyword&#39;, &#39;name&#39;)-&gt;get();</pre><pre>// ค้นหาจากฟิลด์ name และ email<br>-&gt;search(&#39;Keyword&#39;, [&#39;name&#39;, &#39;email&#39;])-&gt;get();</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f7fd7c6da88" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a custom helper in Laravel framework]]></title>
            <link>https://medium.com/@vetosers/create-a-custom-helper-in-laravel-framework-39df458e40e5?source=rss-7edbc90e6252------2</link>
            <guid isPermaLink="false">https://medium.com/p/39df458e40e5</guid>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Natthanon O.]]></dc:creator>
            <pubDate>Mon, 20 Nov 2017 10:44:48 GMT</pubDate>
            <atom:updated>2017-11-28T13:53:55.533Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*aCCH418GrsTqzVdEONe33g.png" /></figure><p>Just create file in app or somewhere you want. In my case app\Helpers\Utility.php .</p><p>Then define the path of your custom helper in composer.json like this.</p><pre>&quot;autoload&quot;: {<br>    &quot;classmap&quot;: [<br>        &quot;database/seeds&quot;,<br>        &quot;database/factories&quot;<br>    ],<br>    &quot;psr-4&quot;: {<br>        &quot;App\\&quot;: &quot;app/&quot;<br>    },<br>    &quot;files&quot;: [<br>        &quot;app/Helpers/Utility.php&quot;<br>    ]<br>},</pre><p>Finally run this command composer dump-autoload for re-generate the autoload.php file.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39df458e40e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>