<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog - Hi You, I am Tade</title>
	<atom:link href="https://hoangthuc.com/category/blog/feed/" rel="self" type="application/rss+xml" />
	<link>https://hoangthuc.com/category/blog/</link>
	<description></description>
	<lastBuildDate>Sat, 07 Dec 2024 14:46:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://hoangthuc.com/wp-content/uploads/2024/02/logoTH-2-150x150.png</url>
	<title>Blog - Hi You, I am Tade</title>
	<link>https://hoangthuc.com/category/blog/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Cách gỡ bỏ Postman hoàn toàn trên macOS</title>
		<link>https://hoangthuc.com/cach-go-bo-postman-hoan-toan-tren-macos/</link>
		
		<dc:creator><![CDATA[Hoàng Thức]]></dc:creator>
		<pubDate>Sat, 07 Dec 2024 14:45:49 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Thủ thuật máy tính]]></category>
		<guid isPermaLink="false">https://hoangthuc.com/?p=962</guid>

					<description><![CDATA[<p>Để gỡ bỏ Postman trên macOS, bạn có thể làm theo các bước sau: 1. Xóa ứng dụng Postman 2. Xóa tệp cấu hình và dữ liệu Postman lưu các tệp cấu hình trong thư mục Library. Để xóa các tệp này: 3. Làm sạch thùng rác 4. Kiểm tra lại Nếu bạn đã thực [&#8230;]</p>
<p>The post <a href="https://hoangthuc.com/cach-go-bo-postman-hoan-toan-tren-macos/">Cách gỡ bỏ Postman hoàn toàn trên macOS</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Để gỡ bỏ <strong>Postman</strong> trên macOS, bạn có thể làm theo các bước sau:</p>



<h4 class="wp-block-heading">1. <strong>Xóa ứng dụng Postman</strong></h4>



<ul class="wp-block-list">
<li>Mở <strong>Finder</strong>.</li>



<li>Chuyển đến thư mục <strong>Applications</strong>.</li>



<li>Kéo ứng dụng <strong>Postman</strong> vào <strong>Trash (Thùng rác)</strong>.</li>
</ul>



<h4 class="wp-block-heading">2. <strong>Xóa tệp cấu hình và dữ liệu</strong></h4>



<p>Postman lưu các tệp cấu hình trong thư mục <strong>Library</strong>. Để xóa các tệp này:</p>



<ol class="wp-block-list">
<li>Mở Finder và nhấn <strong>Cmd + Shift + G</strong> để mở hộp thoại <strong>Go to Folder</strong>.</li>



<li>Nhập các đường dẫn sau và xóa các tệp hoặc thư mục liên quan đến Postman:
<ul class="wp-block-list">
<li><strong>~/Library/Application Support/Postman</strong></li>



<li><strong>~/Library/Caches/com.postmanlabs.mac</strong></li>



<li><strong>~/Library/Preferences/com.postmanlabs.mac.plist</strong></li>



<li><strong>~/Library/Saved Application State/com.postmanlabs.mac.savedState</strong></li>
</ul>
</li>



<li>Kiểm tra trong <strong>~/Library/Logs/</strong> nếu có thư mục nào liên quan đến Postman và xóa nó.</li>
</ol>



<h4 class="wp-block-heading">3. <strong>Làm sạch thùng rác</strong></h4>



<ul class="wp-block-list">
<li>Sau khi xóa tất cả tệp và thư mục liên quan, bạn có thể dọn sạch thùng rác bằng cách nhấn chuột phải vào biểu tượng <strong>Trash</strong> và chọn <strong>Empty Trash</strong>.</li>
</ul>



<h4 class="wp-block-heading">4. <strong>Kiểm tra lại</strong></h4>



<ul class="wp-block-list">
<li>Mở Finder và tìm kiếm từ khóa &#8220;Postman&#8221; để đảm bảo không còn file nào liên quan.</li>
</ul>



<p>Nếu bạn đã thực hiện đúng các bước trên, Postman sẽ được gỡ bỏ hoàn toàn khỏi máy Mac của bạn.</p>



<p></p>
<p>The post <a href="https://hoangthuc.com/cach-go-bo-postman-hoan-toan-tren-macos/">Cách gỡ bỏ Postman hoàn toàn trên macOS</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Cài đặt nodejs với NVM trên AWS Ubuntu 22.4</title>
		<link>https://hoangthuc.com/cai-dat-nodejs-voi-nvm-tren-aws-ubuntu-22-4/</link>
		
		<dc:creator><![CDATA[Hoàng Thức]]></dc:creator>
		<pubDate>Mon, 04 Nov 2024 00:46:51 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<guid isPermaLink="false">https://hoangthuc.com/?p=952</guid>

					<description><![CDATA[<p>Để cài đặt Node.js với NVM (Node Version Manager) trên AWS Ubuntu 22.04, bạn có thể làm theo các bước sau: 1. Cài đặt NVM Mở terminal của server và chạy lệnh sau để tải và cài đặt NVM: Lệnh này sẽ tải về script cài đặt NVM từ GitHub và chạy nó. 2. Tải [&#8230;]</p>
<p>The post <a href="https://hoangthuc.com/cai-dat-nodejs-voi-nvm-tren-aws-ubuntu-22-4/">Cài đặt nodejs với NVM trên AWS Ubuntu 22.4</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Để cài đặt Node.js với NVM (Node Version Manager) trên AWS Ubuntu 22.04, bạn có thể làm theo các bước sau:</p>



<h3 class="wp-block-heading"><strong>1. Cài đặt NVM</strong></h3>



<p>Mở terminal của server và chạy lệnh sau để tải và cài đặt NVM:</p>



<p><pre class="brush: bash; title: ; notranslate">curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash</pre></p>



<p>Lệnh này sẽ tải về script cài đặt NVM từ GitHub và chạy nó.</p>



<h3 class="wp-block-heading"><strong>2. Tải lại shell hoặc khởi động lại terminal</strong></h3>



<p>Sau khi cài đặt NVM, bạn cần tải lại shell của mình để NVM hoạt động:</p>



<p><pre class="brush: bash; title: ; notranslate">source ~/.bashrc</pre></p>



<p>Hoặc thoát và mở lại terminal.</p>



<h3 class="wp-block-heading"><strong>3. Kiểm tra cài đặt NVM</strong></h3>



<p>Để kiểm tra xem NVM đã được cài đặt thành công chưa, chạy lệnh:</p>



<p><pre class="brush: bash; title: ; notranslate">nvm --version</pre></p>



<p>Nếu bạn thấy phiên bản của NVM, tức là NVM đã cài đặt thành công.</p>



<h3 class="wp-block-heading"><strong>4. Cài đặt Node.js</strong></h3>



<p>Dùng NVM để cài đặt phiên bản Node.js mà bạn cần. Ví dụ, để cài đặt Node.js phiên bản 20, chạy lệnh:</p>



<p><pre class="brush: bash; title: ; notranslate">nvm install 20</pre></p>



<p>NVM sẽ tự động tải và cài đặt phiên bản Node.js 20.</p>



<h3 class="wp-block-heading"><strong>5. Đặt Node.js phiên bản mặc định</strong></h3>



<p>Nếu bạn muốn đặt Node.js phiên bản 20 làm mặc định, chạy:</p>



<p><pre class="brush: bash; title: ; notranslate">nvm alias default 20</pre></p>



<p>Bây giờ, mỗi lần bạn mở terminal mới, NVM sẽ tự động sử dụng Node.js phiên bản 20.</p>



<h3 class="wp-block-heading"><strong>6. Kiểm tra phiên bản Node.js và NPM</strong></h3>



<p>Sau khi cài đặt, bạn có thể kiểm tra phiên bản Node.js và NPM bằng các lệnh:</p>



<p><pre class="brush: bash; title: ; notranslate">node -v 
npm -v</pre></p>



<p>Lúc này, Node.js đã được cài đặt trên server AWS Ubuntu 22.04 của bạn thông qua NVM, và bạn có thể bắt đầu sử dụng.</p>



<p></p>
<p>The post <a href="https://hoangthuc.com/cai-dat-nodejs-voi-nvm-tren-aws-ubuntu-22-4/">Cài đặt nodejs với NVM trên AWS Ubuntu 22.4</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>The ACME server can not issue a certificate for email with IP address</title>
		<link>https://hoangthuc.com/the-acme-server-can-not-issue-a-certificate-for-email-with-ip-address/</link>
					<comments>https://hoangthuc.com/the-acme-server-can-not-issue-a-certificate-for-email-with-ip-address/#comments</comments>
		
		<dc:creator><![CDATA[Hoàng Thức]]></dc:creator>
		<pubDate>Mon, 11 Oct 2021 13:00:57 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<guid isPermaLink="false">https://hoangthuc.com/?p=812</guid>

					<description><![CDATA[<p>> 2021/10/11 19:10:10 [INFO] acme: Registering account for admin@X.X.X.X> 2021/10/11 19:10:11 Could not complete registration> acme: error: 400 :: POST :: https://acme-v02.api.letsencrypt.org/acme/new-acct 5 :: urn:ietf:params:acme:error:invalidEmail :: Error creating new account :: contact email “admin@X.X.X.X” has invalid domain : The ACME server can not issue a certificate for an IP address, url:> Certificate generation failed. I was research and [&#8230;]</p>
<p>The post <a href="https://hoangthuc.com/the-acme-server-can-not-issue-a-certificate-for-email-with-ip-address/">The ACME server can not issue a certificate for email with IP address</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p><em>> 2021/10/11 19:10:10 [INFO] acme: Registering account for admin@X.X.X.X</em><br><em>> 2021/10/11 19:10:11 Could not complete registration</em><br><em>> acme: error: 400 :: POST :: https://acme-v02.api.letsencrypt.org/acme/new-acct 5 :: urn:ietf:params:acme:error:invalidEmail :: Error creating new account :: contact email “admin@X.X.X.X” has invalid domain : The ACME server can not issue a certificate for an IP address, url:</em><br><em>> Certificate generation failed.</em></p>



<p>I was research and see a solution. You can edit in path</p>



<p>/usr/local/directadmin/data/users/admin/user.conf</p>



<p>Edit infomation email then run cmd</p>



<p>service directadmin restart</p>



<p>I was success. Comment if you same me :))</p>
<p>The post <a href="https://hoangthuc.com/the-acme-server-can-not-issue-a-certificate-for-email-with-ip-address/">The ACME server can not issue a certificate for email with IP address</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://hoangthuc.com/the-acme-server-can-not-issue-a-certificate-for-email-with-ip-address/feed/</wfw:commentRss>
			<slash:comments>50</slash:comments>
		
		
			</item>
		<item>
		<title>Dữ liệu JSON trong MySQL</title>
		<link>https://hoangthuc.com/du-lieu-json-trong-mysql/</link>
					<comments>https://hoangthuc.com/du-lieu-json-trong-mysql/#comments</comments>
		
		<dc:creator><![CDATA[Hoàng Thức]]></dc:creator>
		<pubDate>Tue, 12 Jan 2021 09:41:28 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Lập trình]]></category>
		<category><![CDATA[MYSQL]]></category>
		<guid isPermaLink="false">https://hoangthuc.com/?p=719</guid>

					<description><![CDATA[<p>Bắt đầu từ Mysql 5.7.8, Mysql hỗ trợ kiểu dữ liệu JSON được xác định nghĩa bởi RFC 7159 , cho phép truy cập vào dữ liệu trong các tài liệu JSON (Javascript Notation Object). Các điểm lợi của việc lưu dữ liệu vào cột dạng JSON: Tự động xác thực các dữ liệu dạng JSON Tối [&#8230;]</p>
<p>The post <a href="https://hoangthuc.com/du-lieu-json-trong-mysql/">Dữ liệu JSON trong MySQL</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><span style="color: #000000;">Bắt đầu từ Mysql 5.7.8, Mysql hỗ trợ kiểu dữ liệu <strong>JSON</strong> được xác định nghĩa bởi <a style="color: #000000;" href="https://tools.ietf.org/html/rfc7159">RFC 7159</a> , cho phép truy cập vào dữ liệu trong các tài liệu <strong>JSON</strong> (Javascript Notation Object).</span><br />
<span style="color: #000000;">Các điểm lợi của việc lưu dữ liệu vào cột dạng <strong>JSON</strong>:</span></p>
<ul>
<li><span style="color: #000000;">Tự động xác thực các dữ liệu dạng JSON</span></li>
<li><span style="color: #000000;">Tối ưu hoá định dạng lưu trữ</span></li>
<li><span style="color: #000000;">Các hàm trong <strong>SQL</strong> hỗ trợ việc thao tác với dữ liệu cột <strong>JSON</strong> như tạo mới, quản lý hay tìm kiếm</span></li>
<li><span style="color: #000000;">Chuẩn hoá, hợp nhất dữ liệu JSON.</span></li>
</ul>
<h2><strong><span style="color: #000000;">Tạo Dữ Liệu JSON</span></strong></h2>
<p><span style="color: #000000;">Dữ liệu dạng <strong>JSON</strong> có 2 dạng phổ biến là Mảng <strong>JSON(Array Json)</strong> và Đối tượng <strong>JSON(Object Json)</strong>. Mảng Json chứa các giá trị được phân tách với nhau bởi dấu , và được đặt bên trong [ và ] :</span></p>
<pre><pre class="brush: sql; title: ; notranslate">&#x5B;&quot;abc&quot;, 10, null, true, false]</pre>
<p><span style="color: #000000;">Đối tượng Json chứa tập hợp các cặp khoá &#8211; giá trị (key &#8211; value) được phân tách với nhau cũng bởi dấu , và được đặt bên trong { và }:</span></p>
<pre><pre class="brush: xml; title: ; notranslate">{&quot;k1&quot;: &quot;value&quot;, &quot;k2&quot;: 10}</pre>
<p><span style="color: #000000;">Tuy nhiên với nhiều trường hợp phức tạp, dữ liệu <strong>JSON</strong> còn có dạng lồng nhau (Nesting):</span></p>
<pre><pre class="brush: xml; title: ; notranslate">&#x5B;99, {&quot;id&quot;: &quot;HK500&quot;, &quot;cost&quot;: 75.99}, &#x5B;&quot;hot&quot;, &quot;cold&quot;]]
{&quot;k1&quot;: &quot;value&quot;, &quot;k2&quot;: &#x5B;10, 20]}</pre>
<p><span style="color: #000000;">trong mảng <strong>JSON</strong> chứ đối tượng <strong>JSON</strong> và ngược lại.</span></p>
<p><span style="color: #000000;">Thay vì tự đặt ra đối tượng JSON, bạn cũng có thể sử dụng <strong>JSON_OBJECT</strong> chức năng tích hợp.</span></p>
<p><span style="color: #000000;">Các <strong>JSON_OBJECT</strong> chức năng chấp nhận một danh sách các cặp khóa / giá trị theo hình thức <strong>JSON_OBJECT(key1, value1, key2, value2, &#8230; key(n), value(n)) </strong>và trả về một đối tượng JSON.</span></p>
<pre><pre class="brush: sql; title: ; notranslate">/* Let's sell some mobilephones */

INSERT INTO `e_store`.`products`( `name` , `brand_id` , `category_id` , `attributes` )

VALUES( 'Desire' , '2' , '2' ,

JSON_OBJECT( &quot;network&quot; , JSON_ARRAY(&quot;GSM&quot; , &quot;CDMA&quot; , &quot;HSPA&quot; , &quot;EVDO&quot;) ,

&quot;body&quot; ,

&quot;5.11 x 2.59 x 0.46 inches&quot; ,

&quot;weight&quot; ,

&quot;143 grams&quot; ,

&quot;sim&quot; ,

&quot;Micro-SIM&quot; ) );

</pre>
<p><span style="color: #000000;">Một chức năng khác mà chúng ta có thể sử dụng để tạo các đối tượng JSON là <strong>JSON_MERGE</strong> hàm.</span></p>
<p><span style="color: #000000;">Các <strong>JSON_MERGE</strong> chức năng có nhiều đối tượng JSON và tạo ra một, tổng hợp đối tượng duy nhất.</span></p>
<pre><pre class="brush: xml; title: ; notranslate">INSERT INTO `e_store`.`products`( `name` , `brand_id` , `category_id` , `attributes` )

VALUES( 'Explorer' , '3' , '3' ,

JSON_MERGE(

'{&quot;sensor_type&quot;: &quot;CMOS&quot;}' ,

'{&quot;processor&quot;: &quot;Digic DV III&quot;}' ,

'{&quot;scanning_system&quot;: &quot;progressive&quot;}' ,

'{&quot;mount_type&quot;: &quot;PL&quot;}' ,

'{&quot;monitor_type&quot;: &quot;LCD&quot;}'

) );</pre>
<h2><strong><span style="color: #000000;">Thao Tác với Dữ Liệu Cột JSON</span></strong></h2>
<ul>
<li><span style="color: #000000;">Hãy tưởng tượng khi bạn muốn lấy một giá trị nào đó trong một cột dữ liệu <strong>JSON</strong>(ở đây lấy giá trị name):</span></li>
</ul>
<pre><pre class="brush: php; title: ; notranslate"> SELECT JSON_EXTRACT('{&quot;id&quot;: 14, &quot;name&quot;: &quot;Aztalan&quot;}', '$.name');
+---------------------------------------------------------+
| JSON_EXTRACT('{&quot;id&quot;: 14, &quot;name&quot;: &quot;Aztalan&quot;}', '$.name') |
+---------------------------------------------------------+
| &quot;Aztalan&quot;                                               |
+---------------------------------------------------------+
</pre>
<p><span style="color: #000000;">Ở đây <strong>Mysql</strong> cung cấp hàm <strong>JSON_EXTRACT</strong>() giúp trả về dữ liệu từ một tài liệu JSON. Dữ liệu được trả về dựa theo đường dẫn cung cấp, trong ví dụ trên chúng ta thấy đường dẫn ở đây là $.name.</span><br />
<span style="color: #000000;">Tìm hiểu sâu hơn về đường dẫn này nhé: $ là kí tự thể hiện tài liệu JSON đang được xét đến , name chính là tên khoá ta muốn lấy. Tuy nhiên với các dạng dữ liệu <strong>JSON</strong> thì đường dẫn lại khác nhau.</span><br />
<span style="color: #000000;">Với dạng Mảng <strong>JSON </strong>thì đường dẫn có dạng $[n] còn với Đối tượng <strong>JSON </strong>là $.key, n là vị trí giá trị chúng ta muốn lấy trong mảng và key là tên khoá của giá trị chúng ta muốn lấy.</span></p>
<pre><pre class="brush: php; title: ; notranslate"> SELECT JSON_EXTRACT('&#x5B;&quot;abc&quot;, 14, &quot;Aztalan&quot;]', '$&#x5B;0]');
+---------------------------------------------------------+
| JSON_EXTRACT('&#x5B;&quot;abc&quot;, 14, &quot;Aztalan&quot;]', '$&#x5B;0]')          |
+---------------------------------------------------------+
| &quot;abc&quot;                                                   |
+---------------------------------------------------------+
</pre>
<p><span style="color: #000000;">Tuy nhiên với trường hợp dữ liệu dạng lồng nhau thì đường dẫn của chúng ta không đơn giản như vậy. Cùng xem ví dụ sau nhé:</span></p>
<pre><pre class="brush: xml; title: ; notranslate">&#x5B;3, {&quot;a&quot;: &#x5B;5, 6], &quot;b&quot;: 10}, &#x5B;99, 100]]</pre>
<p><span style="color: #000000;">Đây là một mảng <strong>JSON</strong> vậy nếu chúng ta muốn lấy giá trị 3 trong mảng thì đường dẫn sẽ là $[0] (trong một array vị trí đầu tiên sẽ bắt đầu là 0), nhưng nếu chọn lấy giá trị thứ 2 ta sẽ có một đối tượng <strong>JSON </strong>{&#8220;a&#8221;: [5, 6], &#8220;b&#8221;: 10} vậy nếu bài toán đặt ra là muốn lấy giá trị của khoá b trong đối tượng <strong>JSON</strong> này thì ta phải có đường dẫn như nào?. Để lấy giá trị của khoá b ta sẽ có đường dẫn là $[1].b. Với tuỳ trường hợp dạng dữ liệu <strong>JSON</strong> ta sẽ có đường dẫn là $[n].key với dạng mảng lồng object <strong>JSON</strong> và $.key[n] mới dạng object lồng mảng <strong>JSON</strong>.</span></p>
<ul>
<li><span style="color: #000000;">Một số hàm phổ biến được Mysql hỗ trợ như <strong>JSON_SET, JSON_INSERT, JSON_REPLACE hay JSON_REMOVE.</strong></span></li>
</ul>
<pre><pre class="brush: php; title: ; notranslate"> SET @j = '&#x5B;&quot;a&quot;, {&quot;b&quot;: &#x5B;true, false]}, &#x5B;10, 20]]';</pre>
<p><span style="color: #000000;"><strong>JSON_SET</strong> () thay thế các giá trị cho các đường dẫn tồn tại và thêm các giá trị cho các đường dẫn không tồn tại:</span></p>
<pre><pre class="brush: php; title: ; notranslate"> SELECT JSON_SET(@j, '$&#x5B;1].b&#x5B;0]', 1, '$&#x5B;2]&#x5B;2]', 2);
+--------------------------------------------+
| JSON_SET(@j, '$&#x5B;1].b&#x5B;0]', 1, '$&#x5B;2]&#x5B;2]', 2) |
+--------------------------------------------+
| &#x5B;&quot;a&quot;, {&quot;b&quot;: &#x5B;1, false]}, &#x5B;10, 20, 2]]      |
+--------------------------------------------+</pre>
<p><span style="color: #000000;"><strong>JSON_INSERT</strong> () thêm các giá trị mới nhưng không thay thế các giá trị hiện có:</span></p>
<pre><pre class="brush: php; title: ; notranslate"> SELECT JSON_INSERT(@j, '$&#x5B;1].b&#x5B;0]', 1, '$&#x5B;2]&#x5B;2]', 2);
+-----------------------------------------------+
| JSON_INSERT(@j, '$&#x5B;1].b&#x5B;0]', 1, '$&#x5B;2]&#x5B;2]', 2) |
+-----------------------------------------------+
| &#x5B;&quot;a&quot;, {&quot;b&quot;: &#x5B;true, false]}, &#x5B;10, 20, 2]]      |
+-----------------------------------------------+</pre>
<p><span style="color: #000000;"><strong>JSON_REPLACE</strong> () thay thế các giá trị hiện có và bỏ qua các giá trị mới:</span></p>
<pre><pre class="brush: php; title: ; notranslate"> SELECT JSON_REPLACE(@j, '$&#x5B;1].b&#x5B;0]', 1, '$&#x5B;2]&#x5B;2]', 2);
+------------------------------------------------+
| JSON_REPLACE(@j, '$&#x5B;1].b&#x5B;0]', 1, '$&#x5B;2]&#x5B;2]', 2) |
+------------------------------------------------+
| &#x5B;&quot;a&quot;, {&quot;b&quot;: &#x5B;1, false]}, &#x5B;10, 20]]             |
+------------------------------------------------+</pre>
<p><span style="color: #000000;"><strong>JSON_REMOVE</strong> () lấy một tài liệu <strong>JSON</strong> và một hoặc nhiều đường dẫn chỉ định các giá trị sẽ bị xóa khỏi tài liệu. Giá trị trả về là tài liệu gốc trừ đi các giá trị được chọn bởi các đường dẫn tồn tại trong tài liệu:</span></p>
<pre><pre class="brush: php; title: ; notranslate">SELECT JSON_REMOVE(@j, '$&#x5B;2]', '$&#x5B;1].b&#x5B;1]', '$&#x5B;1].b&#x5B;1]');
+---------------------------------------------------+
| JSON_REMOVE(@j, '$&#x5B;2]', '$&#x5B;1].b&#x5B;1]', '$&#x5B;1].b&#x5B;1]') |
+---------------------------------------------------+
| &#x5B;&quot;a&quot;, {&quot;b&quot;: &#x5B;true]}]                              |
+---------------------------------------------------+</pre>
<p>The post <a href="https://hoangthuc.com/du-lieu-json-trong-mysql/">Dữ liệu JSON trong MySQL</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://hoangthuc.com/du-lieu-json-trong-mysql/feed/</wfw:commentRss>
			<slash:comments>48</slash:comments>
		
		
			</item>
		<item>
		<title>Phân quyền trong Laravel với Laravel permission</title>
		<link>https://hoangthuc.com/phan-quyen-trong-laravel-voi-laravel-permission/</link>
					<comments>https://hoangthuc.com/phan-quyen-trong-laravel-voi-laravel-permission/#comments</comments>
		
		<dc:creator><![CDATA[Hoàng Thức]]></dc:creator>
		<pubDate>Tue, 04 Aug 2020 16:41:29 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Php]]></category>
		<guid isPermaLink="false">https://hoangthuc.com/?p=658</guid>

					<description><![CDATA[<p>Laravel permission cho phép chúng ta chia ra 2 thành phần là Vai trò (role) và quyền (permission). 1.Cài đặt Cài đặt Laravel 5.8 hoặc cao hơn Nếu bạn đang có sẵn file config/permission.php bạn phải đổi tên hoặc xóa ngay, bởi vì khi setup thì package sẽ được publishes vào config/permission.php Nếu thỏa mãn 2 điều kiện [&#8230;]</p>
<p>The post <a href="https://hoangthuc.com/phan-quyen-trong-laravel-voi-laravel-permission/">Phân quyền trong Laravel với Laravel permission</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Laravel permission cho phép chúng ta chia ra 2 thành phần là Vai trò (role) và quyền (permission).</p>
<p><strong>1.Cài đặt</strong></p>
<ul>
<li>Cài đặt Laravel 5.8 hoặc cao hơn</li>
<li>Nếu bạn đang có sẵn file <code>config/permission.php</code> bạn phải đổi tên hoặc xóa ngay, bởi vì khi setup thì package sẽ được publishes vào <code>config/permission.php</code></li>
</ul>
<p>Nếu thỏa mãn 2 điều kiện trên rồi chúng ta chạy câu lệnh dưới:</p>
<pre class="brush: php; title: ; notranslate">

composer require spatie/laravel-permission

</pre>
<p>Sau đó, trong <code>config/app.php</code> chúng ta add service provide cho package như sau:</p>
<pre class="brush: php; title: ; notranslate">

'providers' =&amp;gt; &#x5B; // ... Spatie\Permission\PermissionServiceProvider::class, ];

</pre>
<p>Sau đó, publish migration thông qua lệnh:</p>
<pre class="brush: php; title: ; notranslate">

php artisan vendor:publish --provider=&amp;quot;Spatie\Permission\PermissionServiceProvider&amp;quot;

</pre>
<p>Chạy lệnh <code>php artisan migrate</code> và chúng ta sẽ có các bảng như <strong>roles, permissions, role_has_permissions, model_has_roles </strong>và <strong>model_has_permission</strong></p>
<p>&nbsp;</p>
<p><strong>2.Tạo Roles và Permissions</strong></p>
<p>Tạo file mới  <strong>/database/seeds/PermissionsDemoSeeder.php </strong>và code như ví dụ bên dưới</p>
<pre class="brush: php; title: ; notranslate">

use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use Spatie\Permission\PermissionRegistrar;

class PermissionsDemoSeeder extends Seeder
{
/**
* Create the initial roles and permissions.
*
* @return void
*/
public function run()
{
// Reset cached roles and permissions
app()&#x5B;PermissionRegistrar::class]-&amp;gt;forgetCachedPermissions();

// create permissions
Permission::create(&#x5B;'name' =&amp;gt; 'edit articles']);
Permission::create(&#x5B;'name' =&amp;gt; 'delete articles']);
Permission::create(&#x5B;'name' =&amp;gt;; 'publish articles']);
Permission::create(&#x5B;'name' =&amp;gt; 'unpublish articles']);

// create roles and assign existing permissions
$role1 = Role::create(&#x5B;'name' &amp;gt; 'writer']);
$role1-&amp;gt;givePermissionTo('edit articles');
$role1-&amp;gt;givePermissionTo('delete articles');

$role2 = Role::create(&#x5B;'name' =&amp;gt; 'admin']);
$role2-&amp;gt;givePermissionTo('publish articles');
$role2-&amp;gt;givePermissionTo('unpublish articles');

$role3 = Role::create(&#x5B;'name' =&amp;gt; 'super-admin']);
// gets all permissions via Gate::before rule; see AuthServiceProvider

// create demo users
$user = Factory(App\User::class)-&amp;gt;create(&#x5B;
'name' =&amp;gt; 'Example User',
'email' =&amp;gt; 'test@example.com',
]);
$user-&amp;gt;assignRole($role1);

$user = Factory(App\User::class)-&amp;gt;create(&#x5B;
'name' =&amp;gt; 'Example Admin User',
'email' =&amp;gt; 'admin@example.com',
]);
$user-&amp;gt;assignRole($role2);

$user = Factory(App\User::class)-&amp;gt;create(&#x5B;
'name' =&amp;gt; 'Example Super-Admin User',
'email' =&amp;gt; 'superadmin@example.com',
]);
$user-&amp;gt;assignRole($role3);
}
}

</pre>
<p>Tiếp theo khỏi tạo cơ sở dữ liệu</p>
<pre class="brush: php; title: ; notranslate">

php artisan db:seed --class=PermissionsDemoSeeder

</pre>
<p><strong>3.Trao quyền trực tiếp cho một user</strong><br />
Bạn có thể giao một quyền cho một user như sau:</p>
<pre class="brush: php; title: ; notranslate">
$user-&amp;gt;givePermissionTo('edit articles'); // giao quyền edit articles cho một user nào đó

// nhiều quyền cùng lúc
$user-&amp;gt;givePermissionTo('edit articles', 'delete articles');

// dán 1 mảng 
$user-&amp;gt;givePermissionTo(&#x5B;'edit articles', 'delete articles']);

// xóa 1 quyền
$user-&amp;gt;revokePermissionTo('edit articles');

// thêm quyền
$user-&amp;gt;syncPermissions(&#x5B;'edit articles', 'delete articles']);

//Kiểm tra quyền
$user-&amp;gt;hasPermissionTo('edit articles');
</pre>
<p><strong>4.Trao quyền thông qua roles<br />
</strong>Một roles có thể được trao cho bất cứ <code>users</code> nào bằng cách :</p>
<pre class="brush: php; title: ; notranslate">
$user-&amp;gt;assignRole('writer');

// set nhiều vai trò $user-&amp;gt;assignRole('writer', 'admin'); 
// dán 1 mảng $user-&amp;gt;assignRole(&#x5B;'writer', 'admin']);
// xóa vai trò
$user-&amp;gt;removeRole('writer');
//check xem vai tro đang cần tìm bằng cách :
$user-&amp;gt;hasRole('writer');
// thêm vai trò và clear các vai trò có sẳn từ trước
$user-&amp;gt;syncRoles('admin');
</pre>
<p><strong>5.Sử dụng với middleware</strong><br />
Bạn có thể sử dụng can như một mặc định để giới hạn quyền truy cập cho trang web bằng cách :</p>
<pre class="brush: php; title: ; notranslate">
Route::group(&#x5B;'middleware' =&amp;gt; &#x5B;'can:publish articles']], function () { // });
</pre>
<p>Hoặc nếu bạn không muốn sử dụng mặc định, Laravel permission mang đến cho chúng ta các middleware RoleMiddleware, PermissionMiddleware and RoleOrPermissionMiddleware. Để sử dụng, bạn cần thêm vào app/Http/Kernel.php file như sau:</p>
<pre class="brush: php; title: ; notranslate">
protected $routeMiddleware = &#x5B; 
// ... 
'role' =&amp;gt; \Spatie\Permission\Middlewares\RoleMiddleware::class, 
'permission' =&amp;gt; \Spatie\Permission\Middlewares\PermissionMiddleware::class, 
'role_or_permission' =&amp;gt; \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class, 
];
</pre>
<p>Sau đó chúng ta có thể sữ dung các route:</p>
<pre class="brush: php; title: ; notranslate">
// Chỉ có role là super-admin mới có thể truy cập vào các route của group này 
Route::group(&#x5B;'middleware' =&amp;gt; &#x5B;'role:super-admin']], function () { // }); 
// Chỉ có permission là publish articles thì mới có thể truy cập vào các route của group này 
Route::group(&#x5B;'middleware' =&amp;gt; &#x5B;'permission:publish articles']], function () { // }); 
// Chỉ có role là super-admin hoặc permission là publish articles thì mới có thể truy cập vào các route của group này 
Route::group(&#x5B;'middleware' =&amp;gt; &#x5B;'role:super-admin','permission:publish articles']], function () { // }); 
Route::group(&#x5B;'middleware' =&amp;gt; &#x5B;'role_or_permission:super-admin|edit articles']], function () { // });

// Đối với GET;
Route::get('/admin', function(){
    return view('admin.dashboard');
})-&amp;gt;name('admin')-&amp;gt;middleware('auth')-&amp;gt;middleware(&#x5B;'role:administrator']);
// auth để kiềm tra đăng nhập và role để kiểm tra vai trò. 
// Tất cả những quyền không được phép truy cập sẽ mặc định trả về page 403: 
</pre>
<p><strong>6.Sử dụng trực tiếp trên Blade</strong><br />
Đối với phần view, để hiển thị view tương ứng cho các vai trò, chúng ta có thể sử dụng <code>@can</code>, <code>@cannot</code>, <code>@canany</code>, and <code>@guest</code> để kiểm tra việc xem thông tin hiển thị trên một trang web. Chúng ta làm như sau:</p>
<pre class="brush: php; title: ; notranslate">
@can('edit articles') 
// 
@endcan

// hoặc

@if(auth()-&amp;gt;user()-&amp;gt;can('edit articles') &amp;amp;&amp;amp; $some_other_condition)
  //
@endif

// hoặc
@role('writer')
    I am a writer!
@else
    I am not a writer...
@endrole

 // Kiem tra nhiều hơn như sau:
@hasanyrole($collectionOfRoles)
    Tôi có một hoặc nhiều roles trong điều kiện này
@else
   Tôi không thuộc roles nào ở trên
@endhasanyrole

// hoặc

@hasanyrole('writer|admin')
    Tôi là một writer hoặc admin hoặc cả hai :D
@else
   Tôi không là writer cũng không là admin
@endhasanyrole
</pre>
<p>Vừa rồi mình đã giới thiệu 1 số vấn đề cớ bản trong việc sử dụng package <code>spatie/laravel-permission</code>  trong Laravel để làm tính năng phân quyền. Mong các bạn có thể áp dụng dễ dàng.<br />
Chúc các bạn ngày vui vẻ.</p>
<p>&nbsp;</p>
<p>The post <a href="https://hoangthuc.com/phan-quyen-trong-laravel-voi-laravel-permission/">Phân quyền trong Laravel với Laravel permission</a> appeared first on <a href="https://hoangthuc.com">Hi You, I am Tade</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://hoangthuc.com/phan-quyen-trong-laravel-voi-laravel-permission/feed/</wfw:commentRss>
			<slash:comments>556</slash:comments>
		
		
			</item>
	</channel>
</rss>
