codinghelptech.com/ http://codinghelptech.com/feed Codinghelptech is a tech inspired blog offering Tips, Tricks and Hacks to enhance your overall life experience en contact@codinghelptech.com Copyright 2016Host is not allowed to connect to this MySQL serverhttp://codinghelptech.com/Database/Host-is-not-allowed-to-connect-to-this-MySQL-server<p>If you are trying to connect mysql database from your ip address. For this you use the below command:</p> <pre> # mysql -u database_username -p -h 168.24.86.7 </pre> <p>As you execute the above command. You see the following error displayed on the terminal or command line:</p> <pre> ERROR 1130 (00000): Host '168.24.86.7' OR 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server </pre> <p>In this tutorial, you will learn how to fix the &ldquo;ERROR 1130 (HY000): Host x.x.x.x is not allowed to connect to this MySQL server&rdquo; error in&nbsp;MySQL/MariaDB database deployment&nbsp;on a Linux.</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-medrectangle-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 300px; height: 0px;">&nbsp;</div> <h2>Host is not allowed to connect to this MySQL server</h2> <p>By following these steps, you can troubleshoot and resolve the &ldquo;Host is not allowed to connect to this MySQL server&rdquo; error:</p> <ul> <li>Step 1: Connect to MySQL Server</li> <li>Step 2: To Check Host</li> <li>Step 3: Enable MySQL Access for the Remote</li> <li>Step 4: Give Remote Access from All Host</li> <li>Step 5: Verify by Trying to Remotely Connect to the MySQL Database</li> </ul> <h3>Step 1: Connect to MySQL Server</h3> <p>Firstly, open your terminal and execute the following command to connect mysql server:</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-box-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 250px; height: 0px;">&nbsp;</div> <pre> # mysql -u root -p </pre> <h3>Step 2: To Check Host</h3> <p>Once you have connected to mysql server, execute the following SQL commands to check the user&rsquo;s host:</p> <pre> MariaDB [(none)]&gt; SELECT host FROM mysql.user WHERE user = &quot;database_username&quot;; </pre> <p>After that, you can see the output on the terminal or command line of above-given command, the user is only allowed to connect to the database server from localhost. So, you need to update the user&rsquo;s host as follows.</p> <h3>Step 3: Enable MySQL Access for the Remote</h3> <p>Once you have checked, you need to execute the following&nbsp;GRANT&nbsp;command to enable MySQL access for the remote user from a remote host.</p> <pre> MariaDB [(none)]&gt; GRANT ALL ON database_name.* to 'database_username'@'168.24.86.7' IDENTIFIED BY 'database_password'; MariaDB [(none)]&gt; FLUSH PRIVILEGES; MariaDB [(none)]&gt; SELECT host FROM mysql.user WHERE user = &quot;database_username&quot;;</pre> <p>Note that, please replace &ldquo;168.24.86.7&rdquo; with the IP address of the remote system, and &ldquo;database_password&rdquo; to the password that you want &ldquo;database_username&rdquo; to use:</p> <h3>Step 4: Give Remote Access from All Host</h3> <p>Then execute the following command on the terminal or command line to grant a user remote access from all hosts on a network:</p> <pre> MariaDB [(none)]&gt; GRANT ALL ON database_name.* to 'database_username'@'168.24.86.7.%' IDENTIFIED BY 'database_password';</pre> <h3>Step 5: Verify by Trying to Remotely Connect to the MySQL Database</h3> <p>If you have followed the saree steps given above. So now you can connect to remote MySQL database from your ip address. For this you use the command given below:</p> <pre> # mysql -u database_username -p -h 168.24.86.7 </pre> <p>Note that, please replace &ldquo;168.24.86.7&rdquo; with the IP address of the remote system.</p> <h2>Conclusion</h2> <p>That&rsquo;s all, in this tutorial you have learned how to fix the &ldquo;Host is not allowed to connect to this MySQL server&rdquo; error.</p> Mon, 17 Jul 2023 08:08:24 +0530http://codinghelptech.com/Database/Host-is-not-allowed-to-connect-to-this-MySQL-serverPHP artisan migrate specific migrationhttp://codinghelptech.com/Php/PHP-artisan-migrate-specific-migration<p>To migrate specific migration for tables in Laravel; In this tutorial, you will learn how to migrate specific migration files for tables in Laravel apps.</p> <h2>How to Migrate Specific Migration Files for Tables in Laravel</h2> <p>Using the following steps, you can migrate specific migration files for specific tables in laravel apps:</p> <ul> <li>Step 1: Understand Database Migrations in Laravel</li> <li>Step 2: See Available Migrations</li> <li>Step 3: Run Specific Migration File</li> <li>Step 4: Verify Specific Migration</li> </ul> <h3>Step 1: Understand Database Migrations in Laravel</h3> <p>Before using any migration command in Laravel, get to know about that command. Because the migration command in Laravel directly modifies your database tables using the database schema.</p> <h3>Step 2: See Available Migrations</h3> <p>Now, open your terminal or command prompt and go to your Laravel project root directory. Then execute php artisan to see the list of available commands related to migration.</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-medrectangle-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <pre> php artisan migrate:status </pre> <h3>Step 3: Run Specific Migration File</h3> <p>If you want to migrate a specific migration file for a specific table in Laravel apps. So, open terminal or command prompt and execute the following command into it to migrate specific migration files in laravel apps:</p> <pre> php artisan migrate --path=path/to/migration/file.php </pre> <p>Note:- Please replace&nbsp;<code>path/to/migration/file.php</code>&nbsp;with the actual path to your migration file.</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-box-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <h3>Step 4: Verify Specific Migration</h3> <p>Once you have executed the above migration command, you should be able to see the result displayed on your terminal. And another option is that you can verify its execution by checking the database for any changes specified in the migration file.</p> <h2>Conclusion</h2> <p>That&rsquo;s it; In this tutorial, you have learned how to migrate specific migration files for tables in Laravel apps.</p> Fri, 14 Jul 2023 09:12:16 +0530http://codinghelptech.com/Php/PHP-artisan-migrate-specific-migrationsqlstate(hy000 error 1045) access denied for user laravelhttp://codinghelptech.com/Php/sqlstatehy000-error-1045-access-denied-for-user-laravel<p>If you are working in Laravel application. And you are trying to fetch or&nbsp;insert data from the MySQL database. And then you get this error SQLSTATE[HY000] [1045] Access denied for user &lsquo;root&rsquo;@&rsquo;localhost&rsquo; (using password: YES) and SQLSTATE[HY000] [1045] Access denied for user &lsquo;username&rsquo;@&rsquo;localhost&rsquo; (using password: NO).</p> <p>This type of error comes in two conditions. First of all, you have not configured the database properly with laravel app., or else your Laravel app is cached. In this tutorial, you will find the solution of laravel SQLSTATE[HY000] [1045] Access denied for user &lsquo;root&rsquo;@&rsquo;localhost&rsquo; (using password: YES) and SQLSTATE[HY000] [1045] Access denied for user &lsquo;username&rsquo;@&rsquo;localhost&rsquo; (using password: NO).</p> <h2>Laravel sqlstate(hy000 error 1045) access denied for user &lsquo;root&rsquo;@&rsquo;localhost&rsquo; (using password: YES/NO)</h2> <p>There are two types of errors that occur when you work with MySQL database on Laravel. whose solutions are given below:</p> <ul> <li>Solution 1 &ndash; SQLSTATE[HY000] [1045] Access denied for user &rdquo;@&rsquo;localhost&rsquo; (using password: NO)</li> <li>Solution 2 &ndash; SQLSTATE[HY000] [1045] Access denied for user &lsquo;abua&rsquo;@&rsquo;localhost&rsquo; (using password: YES)</li> </ul> <h3>Solution 1 &ndash; SQLSTATE[HY000] [1045] Access denied for user &rdquo;@&rsquo;localhost&rsquo; (using password: NO)</h3> <p>If you forgot to add the database name, username, and password in your Laravel app. then you will get this error&nbsp;SQLSTATE[HY000] [1045] Access denied for user &rdquo;@&rsquo;localhost&rsquo; (using password: NO).</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-medrectangle-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <pre> DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE= DB_USERNAME= DB_PASSWORD=</pre> <p>For this, you have to open the .env file in the Laravel app and add the database name, username and password.</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-box-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <h3>Solution 2 &ndash; SQLSTATE[HY000] [1045] Access denied for user &lsquo;abua&rsquo;@&rsquo;localhost&rsquo; (using password: YES)</h3> <p>If you have added database details in .env file but still you got this error. SQLSTATE[HY000] [1045] Access denied for user &lsquo;abua&rsquo;@&rsquo;localhost&rsquo; (using password: YES).</p> <p>So for this you have to clear the cache of your Laravel app. You can use the command given below.</p> <p>Clear Configuration Cache: In some cases, Laravel might cache the database configuration.&nbsp;To clear the cache in laravel, run the following command in your Laravel project&rsquo;s root directory:</p> <pre> php artisan config:clear</pre> <h2>Conclusion</h2> <p>In this tutorial, you have found two solutions for SQLSTATE[HY000] [1045] Access denied for user &lsquo;abua&rsquo;@&rsquo;localhost&rsquo; (using password: YES and No) laravel.</p> Thu, 13 Jul 2023 09:21:42 +0530http://codinghelptech.com/Php/sqlstatehy000-error-1045-access-denied-for-user-laravelsqlstate(hy000 error 1045) access denied for user laravelhttp://codinghelptech.com/Php/sqlstatehy000-error-1045-access-denied-for-user-laravel<p>If you are working in Laravel application. And you are trying to fetch or&nbsp;insert data from the MySQL database. And then you get this error SQLSTATE[HY000] [1045] Access denied for user &lsquo;root&rsquo;@&rsquo;localhost&rsquo; (using password: YES) and SQLSTATE[HY000] [1045] Access denied for user &lsquo;username&rsquo;@&rsquo;localhost&rsquo; (using password: NO).</p> <p>This type of error comes in two conditions. First of all, you have not configured the database properly with laravel app., or else your Laravel app is cached. In this tutorial, you will find the solution of laravel SQLSTATE[HY000] [1045] Access denied for user &lsquo;root&rsquo;@&rsquo;localhost&rsquo; (using password: YES) and SQLSTATE[HY000] [1045] Access denied for user &lsquo;username&rsquo;@&rsquo;localhost&rsquo; (using password: NO).</p> <h2>Laravel sqlstate(hy000 error 1045) access denied for user &lsquo;root&rsquo;@&rsquo;localhost&rsquo; (using password: YES/NO)</h2> <p>There are two types of errors that occur when you work with MySQL database on Laravel. whose solutions are given below:</p> <ul> <li>Solution 1 &ndash; SQLSTATE[HY000] [1045] Access denied for user &rdquo;@&rsquo;localhost&rsquo; (using password: NO)</li> <li>Solution 2 &ndash; SQLSTATE[HY000] [1045] Access denied for user &lsquo;abua&rsquo;@&rsquo;localhost&rsquo; (using password: YES)</li> </ul> <h3>Solution 1 &ndash; SQLSTATE[HY000] [1045] Access denied for user &rdquo;@&rsquo;localhost&rsquo; (using password: NO)</h3> <p>If you forgot to add the database name, username, and password in your Laravel app. then you will get this error&nbsp;SQLSTATE[HY000] [1045] Access denied for user &rdquo;@&rsquo;localhost&rsquo; (using password: NO).</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-medrectangle-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <pre> DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE= DB_USERNAME= DB_PASSWORD=</pre> <p>For this, you have to open the .env file in the Laravel app and add the database name, username and password.</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-box-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <h3>Solution 2 &ndash; SQLSTATE[HY000] [1045] Access denied for user &lsquo;abua&rsquo;@&rsquo;localhost&rsquo; (using password: YES)</h3> <p>If you have added database details in .env file but still you got this error. SQLSTATE[HY000] [1045] Access denied for user &lsquo;abua&rsquo;@&rsquo;localhost&rsquo; (using password: YES).</p> <p>So for this you have to clear the cache of your Laravel app. You can use the command given below.</p> <p>Clear Configuration Cache: In some cases, Laravel might cache the database configuration.&nbsp;To clear the cache in laravel, run the following command in your Laravel project&rsquo;s root directory:</p> <pre> php artisan config:clear</pre> <h2>Conclusion</h2> <p>In this tutorial, you have found two solutions for SQLSTATE[HY000] [1045] Access denied for user &lsquo;abua&rsquo;@&rsquo;localhost&rsquo; (using password: YES and No) laravel.</p> Fri, 07 Jul 2023 10:00:01 +0530http://codinghelptech.com/Php/sqlstatehy000-error-1045-access-denied-for-user-laravelGenerate PDF from HTML View using DomPDF in CodeIgniter 4http://codinghelptech.com/Php/Generate-PDF-from-HTML-View-using-DomPDF-in-CodeIgniter-4<p>If you are working on Codeigniter 4 app and at that time, you may want to generate a pdf file from html or views in codeigniter 4 app. Or you are searching how to create a PDF file from the HTML view template using the domPDF library in Codeigniter 4.</p> <p>To generate dynamic pdf using dompdf in Codeigniter 4. In this tutorial guide, you will learn how to generate dynamic pdf using dompdf in Codeigniter 4 and as well as download it.</p> <h2>Generate PDF from HTML View using DomPDF in CodeIgniter 4</h2> <p>Follow the following steps to generate pdf file in codeigniter 4:</p> <ul> <li>Step 1: Download Codeigniter Project</li> <li>Step 2: Basic Configurations</li> <li>Step 3: Setup Database Credentials</li> <li>Step 4: Install Dompdf Library</li> <li>Step 5: Create a Controller</li> <li>Step 6: Create a View</li> <li>Step 7: Define Routes</li> <li>Step 8: Start Development Server</li> </ul> <h3>Step 1: Download Codeigniter Project</h3> <p>In this step, you will download the latest version of Codeigniter 4, Go to this link https://codeigniter.com/download Download Codeigniter 4 fresh new setup and unzip the setup in your local system xampp/htdocs/ . And change the download folder name &ldquo;demo&rdquo;</p> <h3>Step 2: Basic Configurations</h3> <p>Next, you will set some basic configuration on the&nbsp;app/config/app.php&nbsp;file, so let&rsquo;s go to application/config/config.php and open this file on text editor.</p> <p>Set Base URL like this</p> <pre> public $baseURL = 'http://localhost:8080'; To public $baseURL = 'http://localhost/demo/';</pre> <h3>Step 3: Setup Database Credentials</h3> <p>In this step, you need to connect our project to the database. you need to go&nbsp;app/Config/Database.php&nbsp;and open database.php file in text editor. After opening the file in a text editor, you need to set up database credentials in this file like below.</p> <p>public $default = [<br /> &nbsp; &nbsp; 'DSN'&nbsp; &nbsp; &nbsp; =&gt; '',<br /> &nbsp; &nbsp; 'hostname' =&gt; 'localhost',<br /> &nbsp; &nbsp; 'username' =&gt; 'root',<br /> &nbsp; &nbsp; 'password' =&gt; '',<br /> &nbsp; &nbsp; 'database' =&gt; 'demo',<br /> &nbsp; &nbsp; 'DBDriver' =&gt; 'MySQLi',<br /> &nbsp; &nbsp; 'DBPrefix' =&gt; '',<br /> &nbsp; &nbsp; 'pConnect' =&gt; false,<br /> &nbsp; &nbsp; 'DBDebug'&nbsp; =&gt; (ENVIRONMENT !== 'production'),<br /> &nbsp; &nbsp; 'cacheOn'&nbsp; =&gt; false,<br /> &nbsp; &nbsp; 'cacheDir' =&gt; '',<br /> &nbsp; &nbsp; 'charset'&nbsp; =&gt; 'utf8',<br /> &nbsp; &nbsp; 'DBCollat' =&gt; 'utf8_general_ci',<br /> &nbsp; &nbsp; 'swapPre'&nbsp; =&gt; '',<br /> &nbsp; &nbsp; 'encrypt'&nbsp; =&gt; false,<br /> &nbsp; &nbsp; 'compress' =&gt; false,<br /> &nbsp; &nbsp; 'strictOn' =&gt; false,<br /> &nbsp; &nbsp; 'failover' =&gt; [],<br /> &nbsp; &nbsp; 'port'&nbsp; &nbsp; &nbsp;=&gt; 3306,<br /> ];</p> <h3>Step 4: Install Dompdf Library</h3> <p>In this step, install DomPDF plugin using Composer package. So open your terminal and execute the following command on it:</p> <p>composer require dompdf/dompdf</p> <p>After that, Visit&nbsp;app/Config/Autoload.php&nbsp;file and search for&nbsp;<code>$psr4</code>&nbsp;array, here you have to register the dompdf service.</p> <p>public $psr4 = [<br /> &nbsp; &nbsp; APP_NAMESPACE =&gt; APPPATH, // For custom app namespace<br /> &nbsp; &nbsp; 'Config'&nbsp; &nbsp; &nbsp; =&gt; APPPATH . 'Config',<br /> &nbsp; &nbsp; 'Dompdf'&nbsp; &nbsp; &nbsp; =&gt; APPPATH . 'ThirdParty/dompdf/src',<br /> ];</p> <h3>Step 5: Create a Controller</h3> <p>In this step, Visit&nbsp;app/Controllers&nbsp;and create a controller name&nbsp;PdfController.php. In this controller, you need to add the following methods into it:</p> <p>&lt;?php&nbsp;<br /> namespace App\Controllers;<br /> use CodeIgniter\Controller;<br /> &nbsp;<br /> class PdfController extends Controller<br /> {<br /> &nbsp;<br /> &nbsp; &nbsp; public function index()&nbsp;<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; return view('pdf_view');<br /> &nbsp; &nbsp; }<br /> &nbsp;<br /> &nbsp; &nbsp; function htmlToPDF(){<br /> &nbsp; &nbsp; &nbsp; &nbsp; $dompdf = new \Dompdf\Dompdf();&nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; $dompdf-&gt;loadHtml(view('pdf_view'));<br /> &nbsp; &nbsp; &nbsp; &nbsp; $dompdf-&gt;setPaper('A4', 'landscape');<br /> &nbsp; &nbsp; &nbsp; &nbsp; $dompdf-&gt;render();<br /> &nbsp; &nbsp; &nbsp; &nbsp; $dompdf-&gt;stream();<br /> &nbsp; &nbsp; }<br /> &nbsp;<br /> }</p> <h3>Step 6: Create a View</h3> <p>In this step, you need to create one view files name&nbsp;pdf-view.php&nbsp;and update the following code into your file:</p> <p>&lt;!doctype html&gt;<br /> &lt;html lang=&quot;en&quot;&gt;<br /> &lt;head&gt;<br /> &lt;meta charset=&quot;utf-8&quot;&gt;<br /> &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;&gt;<br /> &lt;title&gt;Codeigniter 4 PDF Generate Example - Tutsmake.com&lt;/title&gt;<br /> &lt;link rel=&quot;stylesheet&quot; href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css&quot;&gt;<br /> &lt;/head&gt;<br /> &lt;body&gt;<br /> &lt;div class=&quot;container mt-5&quot;&gt;<br /> &lt;h2&gt;Codeigniter 4 Generate PDF From View using DOMPdf&lt;/h2&gt;<br /> &lt;div class=&quot;d-flex flex-row-reverse bd-highlight&quot;&gt;<br /> &lt;a href=&quot;&lt;?php echo base_url('PdfController/htmlToPDF') ?&gt;&quot; class=&quot;btn btn-primary&quot;&gt;<br /> Download PDF<br /> &lt;/a&gt;<br /> &lt;/div&gt;<br /> &lt;table class=&quot;table table-striped table-hover mt-4&quot;&gt;<br /> &lt;thead&gt;<br /> &lt;tr&gt;<br /> &lt;th&gt;Name&lt;/th&gt;<br /> &lt;th&gt;Profile&lt;/th&gt;<br /> &lt;th&gt;City&lt;/th&gt;<br /> &lt;th&gt;Date&lt;/th&gt;<br /> &lt;th&gt;CTC&lt;/th&gt;<br /> &lt;/tr&gt;<br /> &lt;/thead&gt;<br /> &lt;tbody&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Airi Satou&lt;/td&gt;<br /> &lt;td&gt;Accountant&lt;/td&gt;<br /> &lt;td&gt;Tokyo&lt;/td&gt;<br /> &lt;td&gt;33&lt;/td&gt;<br /> &lt;td&gt;2008/11/28&lt;/td&gt;<br /> &lt;td&gt;$162,700&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Angelica Ramos&lt;/td&gt;<br /> &lt;td&gt;Chief Executive Officer (CEO)&lt;/td&gt;<br /> &lt;td&gt;London&lt;/td&gt;<br /> &lt;td&gt;47&lt;/td&gt;<br /> &lt;td&gt;2009/10/09&lt;/td&gt;<br /> &lt;td&gt;$1,200,000&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Ashton Cox&lt;/td&gt;<br /> &lt;td&gt;Junior Technical Author&lt;/td&gt;<br /> &lt;td&gt;San Francisco&lt;/td&gt;<br /> &lt;td&gt;66&lt;/td&gt;<br /> &lt;td&gt;2009/01/12&lt;/td&gt;<br /> &lt;td&gt;$86,000&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Bradley Greer&lt;/td&gt;<br /> &lt;td&gt;Software Engineer&lt;/td&gt;<br /> &lt;td&gt;London&lt;/td&gt;<br /> &lt;td&gt;41&lt;/td&gt;<br /> &lt;td&gt;2012/10/13&lt;/td&gt;<br /> &lt;td&gt;$132,000&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Brenden Wagner&lt;/td&gt;<br /> &lt;td&gt;Software Engineer&lt;/td&gt;<br /> &lt;td&gt;San Francisco&lt;/td&gt;<br /> &lt;td&gt;28&lt;/td&gt;<br /> &lt;td&gt;2011/06/07&lt;/td&gt;<br /> &lt;td&gt;$206,850&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Brielle Williamson&lt;/td&gt;<br /> &lt;td&gt;Integration Specialist&lt;/td&gt;<br /> &lt;td&gt;New York&lt;/td&gt;<br /> &lt;td&gt;61&lt;/td&gt;<br /> &lt;td&gt;2012/12/02&lt;/td&gt;<br /> &lt;td&gt;$372,000&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Bruno Nash&lt;/td&gt;<br /> &lt;td&gt;Software Engineer&lt;/td&gt;<br /> &lt;td&gt;London&lt;/td&gt;<br /> &lt;td&gt;38&lt;/td&gt;<br /> &lt;td&gt;2011/05/03&lt;/td&gt;<br /> &lt;td&gt;$163,500&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Caesar Vance&lt;/td&gt;<br /> &lt;td&gt;Pre-Sales Support&lt;/td&gt;<br /> &lt;td&gt;New York&lt;/td&gt;<br /> &lt;td&gt;21&lt;/td&gt;<br /> &lt;td&gt;2011/12/12&lt;/td&gt;<br /> &lt;td&gt;$106,450&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Cara Stevens&lt;/td&gt;<br /> &lt;td&gt;Sales Assistant&lt;/td&gt;<br /> &lt;td&gt;New York&lt;/td&gt;<br /> &lt;td&gt;46&lt;/td&gt;<br /> &lt;td&gt;2011/12/06&lt;/td&gt;<br /> &lt;td&gt;$145,600&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;tr&gt;<br /> &lt;td&gt;Cedric Kelly&lt;/td&gt;<br /> &lt;td&gt;Senior Javascript Developer&lt;/td&gt;<br /> &lt;td&gt;Edinburgh&lt;/td&gt;<br /> &lt;td&gt;22&lt;/td&gt;<br /> &lt;td&gt;2012/03/29&lt;/td&gt;<br /> &lt;td&gt;$433,060&lt;/td&gt;<br /> &lt;/tr&gt;<br /> &lt;/tbody&gt;<br /> &lt;/table&gt;<br /> &lt;/div&gt;<br /> &lt;/body&gt;<br /> &lt;/html&gt;</p> <h3>Step 7: Define Routes</h3> <p>In this step, you need to create a route that renders the table into the view, place the following code in&nbsp;app/Config/Routes.php&nbsp;file.</p> <p>$routes-&gt;get('/', 'PdfController::index');</p> <h3>Step 8: Start Development Server</h3> <p>In this step, open your terminal and execute the following command to start development sever:</p> <pre> php spark serve</pre> <p>Then, Go to the browser and hit below the URL:</p> <pre> http://localhost:8080</pre> <h2>Conclusion</h2> <p>In this Codeigniter 4 generate pdf from views using dompdf library example. In this tutorial you have successfully generated pdf file from view using dompdf library in codeigniter 4.</p> Wed, 28 Jun 2023 09:17:33 +0530http://codinghelptech.com/Php/Generate-PDF-from-HTML-View-using-DomPDF-in-CodeIgniter-4How to Call External API in Laravelhttp://codinghelptech.com/Php/How-to-Call-External-API-in-Laravel<p>Call external APIs in laravel 10/9/8/7 apps; In this tutorial, you will learn how to send http get, post, put and delete request to call external APIs in laravel from controller, blade and model.</p> <p>Sometimes, you need to call external APIs in laravel controller, blade, and model, So you can GET, POST, PUT, DELETE, requests with headers for that.</p> <h2>How to Call External APIs in Laravel Apps</h2> <p>Let&rsquo;s use the following methods to call external APIs from the controller, blade, and model in laravel 10/9/8/7/6:</p> <ul> <li>Method 1: Laravel Call GET Request API</li> <li>Method 2: Laravel Call POST Request API</li> </ul> <h3>Method 1: Laravel Call GET Request API</h3> <p>Let&rsquo;s use the following controller method to call or send curl http get request in laravel:</p> <pre> &lt;?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Http; class PostController extends Controller { /** * Write code on Method * * @return response() */ public function index() { $response = Http::get('https://jsonplaceholder.typicode.com/posts'); $jsonData = $response-&gt;json(); dd($jsonData); } }</pre> <h3>Method 2: Laravel Call POST Request API</h3> <p>Let&rsquo;s use the following controller method to call or send a curl HTTP post request in laravel</p> <pre> &lt;?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Http; class PostController extends Controller { /** * Write code on Method * * @return response() */ public function store() { $response = Http::post('https://jsonplaceholder.typicode.com/posts', [ 'title' =&gt; 'This is test from tutsmake.com', 'body' =&gt; 'This is test from tutsmake.com as body', ]); $jsonData = $response-&gt;json(); dd($jsonData); } }</pre> <h2>Conclusion</h2> <p>Call external APIs in laravel; In this tutorial, you have learned how to call external APIs in laravel from the controller.</p> Fri, 16 Jun 2023 08:40:45 +0530http://codinghelptech.com/Php/How-to-Call-External-API-in-LaravelUpdate from Select MySQL Examplehttp://codinghelptech.com/Database/Update-from-Select-MySQL-Example<p>If you want to do any manipulation with the data of MySQL database table. Like&nbsp;insert, update, select, and delete, these statements are available in MySQL. But you want to select in the update query itself. So for this, you have to create a query using MySQL.</p> <p>In this tutorial, you will learn how to create select, and update in the same query mysql to modify and fetch data within a MySQL database.</p> <h2>Select and update in same query MySQL</h2> <p>Using the MySQL UPDATE FROM SELECT statement, you can update data in one table based on the values retrieved from another table.</p> <p>Update from Select statement is used to update large amounts of data with a single query. It can be used to update one or multiple columns in a table with values retrieved from another table. This statement can be especially useful when you need to update data in a table based on the results of a complex query.</p> <p>Syntax of the UPDATE FROM SELECT statement:</p> <p>Here is the syntax of the UPDATE FROM SELECT statement in MySQL:</p> <pre> UPDATE table1 SET column1 = (SELECT column2 FROM table2 WHERE condition) WHERE condition;</pre> <p>In this syntax,&nbsp;<code>table1</code>&nbsp;is the name of the table you want to update,&nbsp;<code>column1</code>&nbsp;is the name of the column you want to update, and&nbsp;<code>table2</code>&nbsp;is the name of the table that you want to select data from.&nbsp;<code>column2</code>&nbsp;is the name of the column that contains the values you want to update, and&nbsp;<code>condition</code>&nbsp;is the condition that determines which rows should be updated.</p> <h3>Example update from select MySQL</h3> <p>Let&rsquo;s take an example to understand the UPDATE FROM SELECT statement better.</p> <p>Suppose you have two tables,&nbsp;<code>employees</code>&nbsp;and&nbsp;<code>salaries</code>. The&nbsp;<code>employees</code>&nbsp;table contains the&nbsp;<code>employee_id</code>,&nbsp;<code>first_name</code>,&nbsp;<code>last_name</code>, and&nbsp;<code>salary</code>&nbsp;columns, while the&nbsp;<code>salaries</code>&nbsp;table contains the&nbsp;<code>employee_id</code>&nbsp;and&nbsp;<code>salary</code>&nbsp;columns.And you want to update the&nbsp;<code>salary</code>&nbsp;column in the&nbsp;<code>employees</code>&nbsp;table with the values obtained from the&nbsp;<code>salaries</code>&nbsp;table. you can do this using the below given MySQL update from select query:</p> <pre> UPDATE employees SET salary = (SELECT salary FROM salaries WHERE employees.employee_id = salaries.employee_id) WHERE EXISTS (SELECT 1 FROM salaries WHERE employees.employee_id = salaries.employee_id); </pre> <p>In this query, you are updating the&nbsp;<code>salary</code>&nbsp;column in the&nbsp;<code>employees</code>&nbsp;table with the values obtained from the&nbsp;<code>salary</code>&nbsp;column in the&nbsp;<code>salaries</code>&nbsp;table. The condition&nbsp;<code>employees.employee_id = salaries.employee_id</code>&nbsp;ensures that only the salaries of matching employees are updated. The&nbsp;<code>EXISTS</code>&nbsp;subquery is used to avoid updating rows where there is no match in the&nbsp;<code>salaries</code>&nbsp;table.</p> <h2>Conclusion</h2> <p>That&rsquo;s it, in this tutorial, you have learned how to use update and select statements in the same query in Mysql. By using this statement, developers can simplify their code and improve the performance of their database queries.</p> Wed, 07 Jun 2023 08:13:24 +0530http://codinghelptech.com/Database/Update-from-Select-MySQL-ExampleInsert into a table or update if exists MySQLhttp://codinghelptech.com/Database/Insert-into-a-table-or-update-if-exists-MySQL<p>When working with MySQL databases, there are several ways to insert data into a table or update an existing record if it already exists. Three commonly used methods are INSERT IGNORE, REPLACE, and INSERT &hellip; ON DUPLICATE KEY UPDATE.</p> <p>MySQL insert or update if exists with and without a primary key; In this tutorial, you will learn how to insert into a table or update if exists mysql.</p> <h2>Insert into a MySQL table or update if exists</h2> <p>There are three different methods and each of these methods has its own advantages and disadvantages, depending on the specific use case. It is important to understand the differences between these methods and choose the one that best fits your needs for&nbsp;inserting into the MySQL table&nbsp;or updating if exists:</p> <ul> <li>Using&nbsp;INSERT IGNORE</li> <li>Using&nbsp;REPLACE</li> <li>Using&nbsp;INSERT &hellip; ON DUPLICATE KEY UPDATE</li> </ul> <h3>Using&nbsp;INSERT IGNORE</h3> <p>The &ldquo;INSERT IGNORE&rdquo; statement in MySQL is used to insert data into a table while ignoring any duplicate entries. When a user attempts to insert data into a table using the &ldquo;INSERT IGNORE&rdquo; statement, MySQL will first check if a row with the same values already exists in the table. If a duplicate row is found, MySQL will ignore the insertion request and move on to the next one.</p> <p>For example, our&nbsp;<code>users</code>&nbsp;table might contain a few records already:</p> <pre> mysql&gt; SELECT * FROM users LIMIT 3; +----+-------------------------+---------------------+----------------+ | id | Name | last_name | year_of_birth | +----+-------------------------+---------------------+----------------+ | 1 | In Search of Lost Time | Marcel Proust | 1913 | | 2 | Ulysses | James Joyce | 1922 | | 3 | Don Quixote | Miguel de Cervantes | 1605 | +----+-------------------------+---------------------+----------------+ 3 rows in set (0.00 sec)</pre> <p>If you have a large batch of new and existing data to&nbsp;<code>INSERT</code>&nbsp;and part of that data contains a matching value for the&nbsp;<code>id</code>&nbsp;field (which is a&nbsp;<code>UNIQUE</code>&nbsp;<code>PRIMARY_KEY</code>&nbsp;in the table), using a basic&nbsp;<code>INSERT</code>&nbsp;will produce an expected error:</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-medrectangle-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <pre> mysql&gt; INSERT INTO users (id, name, last_name, year_of_birth) VALUES (1, 'testing', 'hella', 1960); ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'</pre> <p>On other way, if you use&nbsp;<code>INSERT IGNORE</code>, the duplication attempt is ignored and no resulting errors occur:</p> <pre> mysql&gt; INSERT IGNORE INTO users (id, name, last_name, year_of_birth) VALUES (1, 'hello', 'world', 1960); Query OK, 0 rows affected (0.00 sec)</pre> <h3>Using&nbsp;REPLACE</h3> <p>The REPLACE statement in MySQL is similar to the INSERT statement, but it has the added functionality of checking if a row with the same primary key or unique index already exists. If it does, the existing row is first deleted and then replaced with the new values. If it doesn&rsquo;t exist, a new row is inserted with the specified values.</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-box-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <p>For example, the REPLACE statement in MySQL is as follows:</p> <pre> mysql&gt; REPLACE INTO users (id, name, last_name, year_of_birth) VALUES (1, 'helm', 'Dr', 1960); Query OK, 2 rows affected (0.00 sec)</pre> <p>The REPLACE statement will first check if a row with the same primary key or unique index already exists in the table. If it does, the existing row will be deleted and replaced with the new values. If it doesn&rsquo;t exist, a new row will be inserted with the specified values.</p> <p>Using&nbsp;INSERT &hellip; ON DUPLICATE KEY UPDATE</p> <p>The INSERT &hellip; ON DUPLICATE KEY UPDATE statement is a powerful feature of MySQL that allows you to insert a new row into a table or update an existing one if it already exists. This statement is particularly useful when you want to add new records to a table or update existing ones without creating any duplicates.</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-banner-1_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <p>For example, the INSERT &hellip; ON DUPLICATE KEY UPDATE statement is as follows:</p> <pre> mysql&gt; SET @id = 1, @name= 'dde', @last_name = 'Proust', @year_of_birth = 1913; INSERT INTO books (id, name, last_name, year_of_birth) VALUES (@id, @name, @last_name, @year_of_birth) ON DUPLICATE KEY UPDATE name = @name, last_name = @last_name, year_of_birth = @year_of_birth;</pre> <p>Notice that you are using normal&nbsp;<code>UPDATE</code>&nbsp;syntax (but excluding the unnecessary&nbsp;<code>table</code>&nbsp;name and&nbsp;<code>SET</code>&nbsp;keyword), and only assigning the&nbsp;<code>non-UNIQUE</code>&nbsp;values. Also, although unnecessary for the&nbsp;<code>ON DUPLICATE KEY UPDATE</code>&nbsp;method to function properly, we&rsquo;ve also opted to utilize&nbsp;<code>user variables</code>&nbsp;so you don&rsquo;t need to specify the actual values we want to&nbsp;<code>INSERT</code>&nbsp;or&nbsp;<code>UPDATE</code>&nbsp;more than once.</p> Fri, 02 Jun 2023 08:46:11 +0530http://codinghelptech.com/Database/Insert-into-a-table-or-update-if-exists-MySQLRemove a Specific Item from an Array in JavaScript by Value and Indexhttp://codinghelptech.com/Javascript/Remove-a-Specific-Item-from-an-Array-in-JavaScript-by-Value-and-Index<p>If you are working with an array in JavaScript. If you need to remove a specific element and item or element from an array by its value or index, then what will you do?</p> <p>In this tutorial, you will learn how to remove specific elements or items from an array of javascript by value and index.</p> <h2>How to Remove a Specific Item/element from an Array in JavaScript by Value and Index</h2> <p>You can easily remove the specific element or item from the array by value and index in javascript using javascript array methods like filter(), indexOf(), and splice():</p> <ul> <li>Using the filter() Method</li> <li>Using the splice() Method</li> <li>Removing an Item from an Array by Index using the splice() method</li> </ul> <h3>Using the filter() Method:</h3> <p>You can remove specific elements or items or element from the array in JavaScript using the filter method.</p> <p>Here is an example to remove an element from an array javascript by value using the filter() method; as follows:</p> <div class="wp-block-syntaxhighlighter-code" style="box-sizing: inherit; padding: 2rem; margin-bottom: 2rem; overflow: auto; border-radius: 1.5rem; font-family: Monaco, "> <pre> let array = [1, 2, 3, 4, 5]; let valueToRemove = 3; array = array.filter(item =&gt; item !== valueToRemove); </pre> </div> <p>In the above example, the&nbsp;<code>filter()</code>&nbsp;method creates a new array by excluding the elements with a value of 3. The resulting array will be&nbsp;<code>[1, 2, 4, 5]</code>.</p> <h3>Using the splice() Method</h3> <p>Using the&nbsp;JavaScript indexOf()&nbsp;and splice() method, you can remove elements from an array of javascript by value.</p> <p>Here is an example to remove an element from an array javascript by value using the js splice() and indexOf() method; as follows:</p> <div class="wp-block-syntaxhighlighter-code" style="box-sizing: inherit; padding: 2rem; margin-bottom: 2rem; overflow: auto; border-radius: 1.5rem; font-family: Monaco, "> <pre> let array = [1, 2, 3, 4, 5]; let valueToRemove = 3; let indexToRemove = array.indexOf(valueToRemove); if (indexToRemove !== -1) { array.splice(indexToRemove, 1); } </pre> </div> <p>In this example,&nbsp;<code>indexOf()</code>&nbsp;is used to find the index of the item or element with the value 3. If the item exists in the array, the&nbsp;<code>splice()</code>&nbsp;method is used to remove one element at the identified index.</p> <h3>Removing an Item from an Array by Index using the splice() method</h3> <p>To remove an item or element from an array based on its index, you can use the&nbsp;<a href="https://www.tutsmake.com/javascript-array-splice-method-by-example/" style="box-sizing: inherit; text-decoration-line: none; transition: all 0.1s ease-in-out 0s; box-shadow: currentcolor 0px 0px 0px inset, currentcolor 0px 1px 0px; color: rgb(229, 153, 0) !important;">js&nbsp;<code>splice()</code>&nbsp;method</a>&nbsp;directly.</p> <p>Here is an example to remove an element from an array javascript by index using the splice() method; as follows:</p> <div class="wp-block-syntaxhighlighter-code" style="box-sizing: inherit; padding: 2rem; margin-bottom: 2rem; overflow: auto; border-radius: 1.5rem; font-family: Monaco, "> <pre> let array = [1, 2, 3, 4, 5]; let indexToRemove = 2; array.splice(indexToRemove, 1); </pre> </div> <p>The&nbsp;<code>splice()</code>&nbsp;the method removes one element from the array at the specified index. In the example above, the item or element at index 2 (value 3) will be removed, resulting in the array&nbsp;<code>[1, 2, 4, 5]</code>.</p> <p>Here&rsquo;s another example that demonstrates how to remove an item or elements by its index using the&nbsp;<code>splice()</code>&nbsp;method:</p> <pre> const array = ['apple', 'banana', 'cherry', 'date']; const indexToRemove = 2; array.splice(indexToRemove, 1); console.log(array); // Output: ['apple', 'banana', 'date'] </pre> <p>In this example, the&nbsp;<code>splice()</code>&nbsp;method is used with the&nbsp;<code>indexToRemove</code>&nbsp;and the number&nbsp;<code>1</code>&nbsp;to indicate that we want to remove only one element at the specified index.</p> <h2>Conclusion</h2> <p>Manipulating arrays is an everyday task in JavaScript development. When it comes to deleting specific items or elements by value or index, JavaScript provides several efficient ways to achieve the desired result. The filter() method is useful for removing items or elements by value, whereas the splice() method can be used to remove items or elements by both value and index. By understanding and using these techniques, you can confidently remove specific objects or elements from arrays in JavaScript while improving your programming skills and productivity.</p> Wed, 31 May 2023 08:22:39 +0530http://codinghelptech.com/Javascript/Remove-a-Specific-Item-from-an-Array-in-JavaScript-by-Value-and-IndexHow to Take Browser Screenshots in Laravelhttp://codinghelptech.com/Php/How-to-Take-Browser-Screenshots-in-Laravel<p>Laravel take/make browser screenshots; Through this tutorial, you will learn how to take/make browser screenshots in laravel using browsershot package.</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-medrectangle-3_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <h2>How to Take Browser Screenshots in Laravel</h2> <p>Use the following steps to make/take browser screenshots in laravel:</p> <ul> <li>Step 1 &ndash; Install Laravel</li> <li>Step 2 &ndash; Install Browsershot Package</li> <li>Step 3 &ndash; Create Route</li> <li>Step 4 &ndash; Create Controller using Artisan</li> <li>Step 5 &ndash; Run Laravel App</li> </ul> <h3>Step 1 &ndash; Install Laravel</h3> <p>First of all, execute the following command on terminal to install laravel app latest version:</p> <pre> composer create-project laravel/laravel blog-example </pre> <h3>Step 2 &ndash; Install Browsershot Package</h3> <p>Then execute the following command on terminal to install browsershot package in laravel apps:</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-medrectangle-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <pre> composer require spatie/browsershot npm install puppeteer --global</pre> <h3>Step 3 &ndash; Create Route</h3> <p>Now, visit routes directory and open web.php file. And create one route for capture browser screenshot:</p> <pre> &lt;?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\TestController; /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the &quot;web&quot; middleware group. Now create something great! | */ Route::get('test', [TestController::class,'index']);</pre> <h3>Step 4 &ndash; Create Controller using Artisan</h3> <p>Execute the following command on terminal to create controller class in laravel apps:</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-box-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <pre> php artisan make:controller TestController</pre> <p>After that, open controller folder/directory and open testcontroller.php. And add the folowing code into it:</p> <pre> &lt;?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Spatie\Browsershot\Browsershot; class TestController extends Controller { /** * Write code on Method * * @return response() */ public function index(Request $request) { Browsershot::url('https://codinghelptech.com') -&gt;setOption('landscape', true) -&gt;windowSize(3840, 2160) -&gt;waitUntilNetworkIdle() -&gt;save('tutsmake.jpg'); dd(&quot;Done&quot;); } }</pre> <h3>Step 5 &ndash; Run Laravel App</h3> <p>Execute the following command on temrinal to start laravel apps:</p> <pre> php artisan serve</pre> <p>Now, Go to your web browser, hit the following URL into it:</p> <pre> http://localhost:8000/demo </pre> <h2>Conclusion</h2> <p>That&rsquo;s all; Through this tutorial, you have learned how to take/make browser screenshots in laravel using browsershot package.</p> Wed, 08 Feb 2023 09:29:42 +0530http://codinghelptech.com/Php/How-to-Take-Browser-Screenshots-in-LaravelOperation not allowed when innodb_forced_recovery > 0http://codinghelptech.com/Database/Operation-not-allowed-when-innodbforcedrecovery--0<p>operation not allowed when innodb_forced_recovery &gt; 0; In this tutorial, you will learn how to fix/resolve operation not allowed when innodb_forced_recovery &gt; 0 in Linux ubuntu apache mysql.</p> <h2>operation not allowed when innodb_forced_recovery &gt; 0</h2> <p>Let&rsquo;s use the following steps to fix or resolve operation not allowed when innodb_forced_recovery &gt; 0 in Linux ubuntu apache mysql:</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-medrectangle-3_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <ul> <li>Step 1 &ndash; Login to Your SSH Server</li> <li>Step 2 &ndash; Edit MySQLd.conf File</li> <li>Step 3 &ndash; Stop and Start MySQL Server</li> </ul> <h3>Step 1 &ndash; Login to Your SSH Server</h3> <p>First of all, you need to login into your ssh server with username and password.</p> <h3>Step 2 &ndash; Edit MySQLd.conf File</h3> <p>Then execute the following command into your terminal:</p> <pre> nano /etc/mysql/mysql.conf.d/mysqld.cnf OR vi /etc/mysql/mysql.conf.d/mysqld.cnf</pre> <p>After that, add commenting out the line to your MySQL.cnf file:</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-medrectangle-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <pre> innodb_force_recovery = 1</pre> <p>in / MySQL.cnf thus:</p> <div class="wp-block-syntaxhighlighter-code" style="box-sizing: inherit; padding: 2rem; margin-bottom: 2rem; overflow: auto; border-radius: 1.5rem; font-family: Monaco, &quot;courier 10 pitch&quot;, Courier, monospace; font-size: 0.875rem; line-height: 1.43;"> <div style="box-sizing: inherit;"> <div class="syntaxhighlighter plain" id="highlighter_974619" style="box-sizing: inherit; width: 708px; margin: 1em 0px !important; position: relative !important; overflow: auto hidden !important; font-size: 1em !important; padding: 0.5em 1em !important;"> <table border="0" cellpadding="0" cellspacing="0" style="background:0px 0px !important; border-radius:0px !important; border-spacing:0px; border:0px !important; box-shadow:0px 0px !important; box-sizing:content-box !important; direction:ltr !important; float:none !important; font-family:monaco,consolas,bitstream vera sans mono,courier new,courier,monospace !important; font-size:1em !important; height:auto !important; inset:auto !important; line-height:1.1em !important; margin:0px !important; outline:0px !important; overflow:visible !important; padding:0px !important; position:static !important; table-layout:auto !important; vertical-align:baseline !important; width:676.5px"> <tbody> <tr> <td style="height:auto !important; vertical-align:baseline !important; width:auto !important"> <div class="line number1 index0 alt2" style="box-sizing: content-box !important; border-radius: 0px !important; background-image: initial !important; background-position: 0px 0px !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border-width: 0px 3px 0px 0px !important; border-top-style: initial !important; border-right-style: solid !important; border-bottom-style: initial !important; border-left-style: initial !important; border-top-color: initial !important; border-right-color: rgb(108, 226, 108) !important; border-bottom-color: initial !important; border-left-color: initial !important; border-image: initial !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.1em !important; margin: 0px 1em 0px 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 0px !important; position: static !important; text-align: right !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; direction: ltr !important; box-shadow: 0px 0px !important; white-space: pre !important;">1</div> </td> <td style="height:auto !important; vertical-align:baseline !important; width:641.213px"> <div class="container" style="box-sizing: content-box !important; border-radius: 0px !important; background: 0px 0px !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; direction: ltr !important; box-shadow: 0px 0px !important;"> <div class="line number1 index0 alt2" style="box-sizing: content-box !important; border-radius: 0px !important; background-image: initial !important; background-position: 0px 0px !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; inset: auto !important; float: none !important; height: auto !important; line-height: 1.1em !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; vertical-align: baseline !important; width: auto !important; font-size: 1em !important; direction: ltr !important; box-shadow: 0px 0px !important; white-space: pre !important;"><code># innodb_force_recovery = 1</code></div> </div> </td> </tr> </tbody> </table> </div> </div> </div> <h3>Step 3 &ndash; Stop and Start MySQL Server</h3> <p>Finally, execute the following command into your terminal to stop and start your mysql server:</p> <div id="google_ads_iframe_/1254144,22587282700/tutsmake_com-box-4_0__container__" style="box-sizing: inherit; border: 0pt none; width: 728px; height: 0px;">&nbsp;</div> <pre> sudo systemctl stop mysql.service ---to shut it down sudo systemctl start mysql.service ---to try and start up and see the reason why it is not starting.</pre> <h2>Conclusion</h2> <p>That&rsquo;s it; In this tutorial, you have learned how to fix/resolve operation not allowed when innodb_forced_recovery &gt; 0 in Linux ubuntu apache mysql.</p> Tue, 10 Jan 2023 10:10:07 +0530http://codinghelptech.com/Database/Operation-not-allowed-when-innodbforcedrecovery--0How to Capture Image from Webcam in Angularhttp://codinghelptech.com/Javascript/How-to-Capture-Image-from-Webcam-in-Angular<p>Capture images from a webcam in angular app; Through this tutorial, we will learn how to capture images from webcam in angular applications.</p> <h2>How to Capture Image from Webcam in Angular</h2> <ul> <li>Step 1 &ndash; Create New Angular App</li> <li>Step 2 &ndash; Install Webcam npm Package</li> <li>Step 3 &ndash; Import WebcamModule</li> <li>Step 4 &ndash; Update Ts File</li> <li>Step 5 &ndash; Update HTML File</li> <li>Step 6 &ndash; Run Angular App</li> </ul> <h3>Step 1 &ndash; Create New Angular App</h3> <p>First of all, open a terminal and execute the following command on the command line or terminal to create a new angular app:</p> <pre> ng new myApp </pre> <h3>Step 2 &ndash; Install Webcam npm Package</h3> <p>Then execute the following command on the command line to install the webcam npm package:</p> <pre> npm i ngx-webcam </pre> <h3>Step 3 &ndash; Import WebcamModule</h3> <p>Visit&nbsp;src/app/&nbsp;directory and open&nbsp;the&nbsp;app.module.ts file. And after that, import the webcam module in the app.module.ts file:</p> <pre> import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { WebcamModule } from 'ngx-webcam'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, WebcamModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }</pre> <h3>Step 4 &ndash; Update Ts File</h3> <p>Visit&nbsp;src/app/&nbsp;directory and open&nbsp;the app.component.ts&nbsp;file. And after that, update the following code into it:</p> <pre> import { Component, OnInit } from '@angular/core'; import { Subject, Observable } from 'rxjs'; import { WebcamImage, WebcamInitError, WebcamUtil } from 'ngx-webcam'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { private trigger: Subject = new Subject(); public webcamImage!: WebcamImage; private nextWebcam: Subject = new Subject(); captureImage = ''; ngOnInit() {} /*------------------------------------------ -------------------------------------------- triggerSnapshot() -------------------------------------------- --------------------------------------------*/ public triggerSnapshot(): void { this.trigger.next(); } /*------------------------------------------ -------------------------------------------- handleImage() -------------------------------------------- --------------------------------------------*/ public handleImage(webcamImage: WebcamImage): void { this.webcamImage = webcamImage; this.captureImage = webcamImage!.imageAsDataUrl; console.info('received webcam image', this.captureImage); } /*------------------------------------------ -------------------------------------------- triggerObservable() -------------------------------------------- --------------------------------------------*/ public get triggerObservable(): Observable { return this.trigger.asObservable(); } /*------------------------------------------ -------------------------------------------- nextWebcamObservable() -------------------------------------------- --------------------------------------------*/ public get nextWebcamObservable(): Observable { return this.nextWebcam.asObservable(); } }</pre> <h3>Step 5 &ndash; Update HTML File</h3> <p>Update html file code, so visit&nbsp;src/app/&nbsp;directory and open app.component.html&nbsp;file. Then update the following code into it:</p> <pre> &lt;div class=&quot;container&quot;&gt; &lt;h1&gt;Angular Webcam Capture Image from Camera - Tutsmake.com&lt;/h1&gt; &lt;div class=&quot;row&quot;&gt; &lt;div class=&quot;col-md-6&quot;&gt; &lt;webcam [trigger]=&quot;triggerObservable&quot; (imageCapture)=&quot;handleImage($event)&quot;&gt;&lt;/webcam&gt; &lt;button class=&quot;btn btn-success&quot; (click)=&quot;triggerSnapshot();&quot;&gt;Take A Snapshot&lt;/button&gt; &lt;/div&gt; &lt;div class=&quot;col-md-6&quot;&gt; &lt;div id=&quot;results&quot;&gt;Your captured image will appear here...&lt;/div&gt; &lt;img src=&quot;{{ captureImage }}&quot; height=&quot;300px&quot;&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;</pre> <h3>Step 6 &ndash; Run Angular App</h3> <p>Execute the following command on the command line to start the angular app:</p> <pre> ng serve </pre> <p>Open a web browser, and type the given URL into it:</p> <pre> http://localhost:4200</pre> <h2>Conclusion</h2> <p>Through this tutorial, we have learned how to capture images from webcams in angular applications.</p> Tue, 12 Jul 2022 08:56:50 +0530http://codinghelptech.com/Javascript/How-to-Capture-Image-from-Webcam-in-Angular8 interesting functions of Laravel Eloquent (ORM)http://codinghelptech.com/Php/8-interesting-functions-of-Laravel-Eloquent-ORM<p>In this article, we&rsquo;ll try to understand more about 8. Laravel Eloquent functions and explains them</p> <p>One of the main concerns for developers is the need to create security queries, create complicated queries, speed up development using databases, making it easier to switch between databases and databases. when using databases within their apps.</p> <p>Laravel utilizes a feature known as Eloquent that solves this problem. Eloquent is an object-relational mapper (ORM) available in the default Laravel framework. Eloquent assists in working with databases by providing an object-oriented way of inserting, updating, and deleting database records in addition to providing a simple interface for performing complicated SQL queries.</p> <p>In this article, we&rsquo;ll try to know more about the 8 Laravel Eloquent functions, and also introduce these functions. Put on your seat belts and prepare to go!</p> <p><strong>1- Replicate</strong></p> <p>How can you accomplish this when you need to duplicate or replicate the database records? To accomplish the same, Laravel has introduced a function known as Replicate.</p> <p>With this function, you can use the function to apply any changes you&rsquo;d like to it and then save it.</p> <p>If you own a store product that you wish to copy and change the title and save it for publication.</p> <p>This method of replication is useful for rapidly duplicating or cloning a database record.</p> <pre> <code><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$product</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span> Product<span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">find</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">1</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$newProduct</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$product</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">replicate</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$newProduct</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">created_at</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span> Carbon<span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">now</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$newProduct</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">save</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span></code> </pre> <p><strong>2- One of Many</strong></p> <p>Let&rsquo;s say there&rsquo;s a User model that has a one-to-many relationship to the post model. Post model. The next step is to select the first and last post for the particular user.</p> <p>You can make use of latestOfMany as well as the oldestOfMany feature that Laravel gives to accomplish this.</p> <pre> <code><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">public</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">function</span> <span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">latestOrder</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">{</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">return</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$this</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">hasOne</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span>Order<span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">class</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">latestOfMany</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">}</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">public</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">function</span> <span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">oldestOrder</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">{</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">return</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$this</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">hasOne</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span>Order<span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">class</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">oldestOfMany</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">}</span></code></pre> <p>The function that is the most recent will return the latest post that was sent from the person using it. The oldestPost function returns the oldest post made by the user in accordance with the primary key model. However, you might need to find a record that is subject to specific requirements. For example, if you want to locate the post that has the highest number of visits, try this:</p> <pre> <code><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">public</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">function</span> <span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">largestOrder</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">{</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">return</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$this</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">hasOne</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span>Order<span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">class</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">ofMany</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'price'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'max'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">}</span></code> </pre> <p>Notes: You can also apply a filter to the results by using a closure function.</p> <p><strong>3- reject</strong></p> <p>This function can be used to eliminate models based on the specified condition.</p> <p>For instance, in the following example, we would like to eliminate items priced over 200 dollars from our collection.</p> <pre> <code><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$collection</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span> <span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">collect</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">[</span><span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">1</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">2</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">3</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">4</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">]</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$filtered</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$collection</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">reject</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">function</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$value</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$key</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">{</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">return</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$value</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span> <span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">2</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">}</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$filtered</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">all</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(112, 128, 144); font-family:inherit; font-size:inherit">// [1, 2]</span></code> </pre> <p><strong>4- isDirty</strong></p> <p>isDirty method identifies if an attribute of the model has changed in the process of retrieving.</p> <p>It is also possible to pass an attribute or two to this method to see whether any changes have been made.<br /> The function isDirty() function is executed when a model is called and returns a true or false value that has changed but hasn&rsquo;t changed.</p> <p>For instance, we have a User model we would like to verify for any modifications.</p> <pre> <code><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$user</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span> User<span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">create</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">[</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'first_name'</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'Taylor'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'last_name'</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'Otwell'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'title'</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'Developer'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">]</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$user</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">title</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'Painter'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$user</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">isDirty</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(112, 128, 144); font-family:inherit; font-size:inherit">// true</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$user</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">isDirty</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'title'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(112, 128, 144); font-family:inherit; font-size:inherit">// true</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$user</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">isDirty</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'first_name'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(112, 128, 144); font-family:inherit; font-size:inherit">// false</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$user</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">isDirty</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">[</span><span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'first_name'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'title'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">]</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(112, 128, 144); font-family:inherit; font-size:inherit">// true</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$user</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">save</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span></code> </pre> <p><strong>5- truncate</strong></p> <p>You can use the truncate feature to erase all the data that is associated with the model from the database.</p> <pre> <code>Post<span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">truncate</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span></code> </pre> <p>The command above will erase all table information that is related to the Post model. Post model!</p> <p><strong>6- is &amp; isNot</strong></p> <p>You might need to verify whether the two models are identical. The functions are is and not will do this for you.</p> <pre> <code><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">if</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$post</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">is</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$anotherPost</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">{</span> <span style="color:rgb(112, 128, 144); font-family:inherit; font-size:inherit">//</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">}</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">if</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$post</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">isNot</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$anotherPost</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">{</span> <span style="color:rgb(112, 128, 144); font-family:inherit; font-size:inherit">//</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">}</span></code> </pre> <p><strong>7- withCount (Count in relation)</strong></p> <p>You can get numbers of rows within a relation by using the function withCount.</p> <p>Let&rsquo;s say you have a user model with an abundance of messages. You can calculate the messages sent by users using the command Count.</p> <p>Check out this example</p> <pre> <code><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$posts</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span> Post<span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">withCount</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'comments'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">get</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">foreach</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$posts</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">as</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$post</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">{</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">echo</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$post</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">comments_count</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">}</span></code> </pre> <p><strong>8- withWhereHas()</strong></p> <p>This method is a way to simplify situations that require repeating the code to filter using whereHas and then pick the record by the use with()&nbsp;<em>(This function is available starting with Laravel version&nbsp;<a href="https://laravel-news.com/laravel-9-16-0" rel="nofollow" style="box-sizing: border-box; background-color: transparent; color: rgb(34, 34, 34); transition: color 0.2s ease 0s, background-color 0.2s ease 0s, text-shadow 0.2s ease 0s, box-shadow 0.2s ease 0s, border 0.2s ease 0s;" target="_blank">9.16.0</a>&nbsp;and up)</em></p> <pre> <code><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$posts</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span> Post<span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">whereHas</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'comments'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">function</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span>Builder <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$query</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">{</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$query</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">where</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'content'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'like'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'code%'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">}</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">get</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span> <span style="color:rgb(112, 128, 144); font-family:inherit; font-size:inherit">//Using the withWhereHas method, you can simplify your code around this use case:</span> Post<span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">:</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">withWhereHas</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'products'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> fn <span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$query</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span> <span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">=</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span> <span style="color:rgb(241, 129, 6); font-family:inherit; font-size:inherit">$query</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">where</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'enabled'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">true</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">-</span><span style="color:rgb(199, 44, 76); font-family:inherit; font-size:inherit">&gt;</span><span style="color:rgb(0, 119, 170); font-family:inherit; font-size:inherit">where</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">(</span><span style="color:rgb(64, 123, 8); font-family:inherit; font-size:inherit">'sale'</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">,</span> <span style="color:rgb(153, 0, 85); font-family:inherit; font-size:inherit">true</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">)</span><span style="color:rgb(95, 95, 95); font-family:inherit; font-size:inherit">;</span></code></pre> Mon, 11 Jul 2022 09:34:23 +0530http://codinghelptech.com/Php/8-interesting-functions-of-Laravel-Eloquent-ORMHow to Enable CORS in Angular 14http://codinghelptech.com/Javascript/How-to-Enable-CORS-in-Angular-14<p>Enable cors in angular 14; In this tutorial, we will learn to handle CORS (Cross-Origin Resource Sharing) issues in Angular 12/13/14 Applications and solve CROS related issues in Angular apps.</p> <p>Cross-origin resource sharing (CORS)&nbsp;is a standard that manages communication between 2 or multiple domains.</p> <p>Let&rsquo;s say, we have a backend server working on&nbsp;<code>http://localhost:3000/api</code>&nbsp;and we want to pass all the API calls to&nbsp;<code>http://localhost:4200/api</code>&nbsp;backend server. So, we need to setting proxy in backend in angular apps.</p> <h2>How to Fixing CORS Issue in Angular 14</h2> <p>Just follow the following steps to enable cors or fix cors (Cross-Origin Resource Sharing) issue in angular 12/13/14 apps:</p> <ul> <li>Step 1 &ndash; Create proxy.conf.json File</li> <li>Step 2 &ndash; Add Proxy Configuration values in angular.json</li> </ul> <h3>Step 1 &ndash; Create proxy.conf.json File</h3> <p>First of all, create a&nbsp;proxy.conf.json&nbsp;file and add the following code into it; is as follows:</p> <pre> { &quot;/api/*&quot;: { &quot;target&quot;: &quot;http://localhost:3000&quot;, &quot;secure&quot;: false, &quot;logLevel&quot;: &quot;debug&quot; } }</pre> <h3>Step 2 &ndash; Add Proxy Configuration values in angular.json</h3> <p>To register a proxy configuration, we need to go to the&nbsp;<code>angular.json</code>&nbsp;file and update the following code inside the&nbsp;<code>serve/options</code>. It will set the&nbsp;<code>src/proxy.conf.json</code>&nbsp;file in our Angular app:</p> <pre> &quot;architect&quot;: { &quot;serve&quot;: { &quot;builder&quot;: &quot;@angular-devkit/build-angular:dev-server&quot;, &quot;options&quot;: { &quot;browserTarget&quot;: &quot;project-name:build&quot;, &quot;proxyConfig&quot;: &quot;src/proxy.conf.json&quot; }, } }</pre> <p>Now, we are all set to start the development server with the current proxy configuration, So, execute the following command on command line:</p> <pre> ng serve --open</pre> <h2>Conclusion</h2> <p>In this tutorial, we have learned to handle CORS (Cross-Origin Resource Sharing) issues in Angular 12/13/14 Applications and solve CROS-related issues in Angular apps.</p> Fri, 08 Jul 2022 09:16:53 +0530http://codinghelptech.com/Javascript/How-to-Enable-CORS-in-Angular-14How to Install Remote Desktop (xrdp) on Ubuntu 22.04http://codinghelptech.com/Tech-News/How-to-Install-Remote-Desktop-xrdp-on-Ubuntu-2204<p>Install remote desktop (xrdp) on linux ubuntu 22.04; Through this tutorial, we will learn how to install and configure XRDP (remote desktop) on linux ubuntu 22.04 system.</p> <p>xrdp is a free and open-source implementation of Microsoft RDP (Remote Desktop Protocol) server that enables operating systems other than Microsoft Windows (such as Linux and BSD-style operating systems)&nbsp;to provide a fully functional RDP-compatible remote desktop experience.</p> <h2>How to Install Remote Desktop (xrdp) on Ubuntu 22.04</h2> <p>Follow the following steps to install XRDP (remote desktop) on linux ubuntu 22.04 system:</p> <ul> <li>Step 1 &ndash; Update System Dependencies</li> <li>Step 2 &ndash; Install XRDP</li> <li>Step 3 &ndash; Configure XRDP</li> <li>Step 4 &ndash; Configure System Firewall</li> <li>Step 5 &ndash; Connect to Remote Desktop</li> </ul> <h3>Step 1 &ndash; Update System Dependencies</h3> <p>First of all, open terminal and execute the following command on command line to update system dependencies:</p> <pre> sudo apt update</pre> <h3>Step 2 &ndash; Install XRDP</h3> <p>Then execute the following commands to install XRDP on Ubuntu system:</p> <pre> sudo apt install xrdp -y </pre> <p>After installation; we can use the following command to check the status:</p> <pre> sudo systemctl status xrdp </pre> <h3>Step 3 &ndash; Configure XRDP</h3> <p>The xrdp session uses a certificate key file&nbsp;&ldquo;/etc/ssl/private/ssl-cert-snakeoil.key&rdquo;, which plays an important role with remote desktop. So, use the following command to create it:</p> <pre> sudo usermod -a -G ssl-cert xrdp </pre> <p>And restart the Xrdp service by executing the following command:</p> <pre> sudo systemctl restart xrdp </pre> <h3>Step 4 &ndash; Configure System Firewall</h3> <p>The XRDP service listens on standard remote desktop port 3389. And if we need to adjust the firewall to allow access to port 3389 for the remote systems.</p> <p>Then execute the following command on command line to open port 3389 for the LAN network:</p> <pre> sudo ufw allow from 192.168.1.0/24 to any port 3389 </pre> <p>Reload the UFW to apply the new rules.</p> <pre> sudo ufw reload </pre> <h3>Step 5 &ndash; Connect to Remote Desktop</h3> <ul> <li>Now, On the Windows system launch the RDP client</li> <li>Once the rdp client connected successfully, the remote system prompt for authentication. Enter the login credentials of the remote Ubuntu system to get remote desktop access.</li> <li>Once the successful authentication, we will get access to Ubuntu remote desktop.</li> </ul> <h2>Conclusion</h2> <p>Through this tutorial, we have learned how to install and configure XRDP on Ubuntu 20.04 desktop system.</p> Mon, 06 Jun 2022 09:03:20 +0530http://codinghelptech.com/Tech-News/How-to-Install-Remote-Desktop-xrdp-on-Ubuntu-2204Python Data Types with Examplehttp://codinghelptech.com/Python/Python-Data-Types-with-Example<p>In this python data types tutorial, you will learn about python data types in detail with example</p> <h2>Data Types in Python</h2> <h3>What is data types in python?</h3> <p>In Python programming language, a data type defines the type of a variable. Python programming does not require defining the data type of a variable. It is a dynamic type of language. The interpreter implicitly binds the value with its type.</p> <h3>Types of data types in python</h3> <p>There are various data types in Python. Some of the important types are listed below:</p> <ul> <li>Numbers Data Type</li> <li>List Data Type</li> <li>Tuple Data Type</li> <li>Strings Data Type</li> <li>Set Data Type</li> <li>Dictionary Data Type</li> </ul> <p>Note:-&nbsp;If you want to check the data type of a variable, what is the data type of the variable, then type () function is used to check the data type of a variable in Python.</p> <p>In Python, below is the program for data type checking:</p> <p>a = 'string'&nbsp;<br /> b = 50&nbsp;<br /> c = 10.5&nbsp;<br /> &nbsp;<br /> print(type(a));&nbsp; &nbsp;<br /> print(type(b));&nbsp; &nbsp;<br /> print(type(c));&nbsp;&nbsp;</p> <p>The output of the above program is following:</p> <p>&lt;type 'str'&gt;<br /> &lt;type 'int'&gt;<br /> &lt;type 'float'&gt;&nbsp;</p> <h3>Numbers Data Type</h3> <p>In python programming, Integer, floating-point numbers, and complex numbers under the category of Python numbers. Those you define as int, float and complex classes.</p> <p>For example:</p> <p>a = 10<br /> print(a, &quot;is of type&quot;, type(a))<br /> &nbsp;<br /> a = 50.0<br /> print(a, &quot;is of type&quot;, type(a))<br /> &nbsp;<br /> a = 11+2j<br /> print(a, &quot;is complex number?&quot;, isinstance(11+2j,complex))</p> <p>Output of the above program is following:</p> <p>10 is of type &lt;class 'int'&gt;<br /> 50.0 is of type &lt;class 'float'&gt;<br /> (11+2j) is complex number? True</p> <h3>List Data Type</h3> <p>In python programming, list data types hold different types of data. it does not need to be of the same type. The items stored in the list are separated with a comma (,) and enclosed within square brackets [].</p> <p>Note:-&nbsp;List data types are alike to arrays in PHP, C</p> <p>You can use a slicing operator [] to extract items from a list.</p> <p>For example:</p> <p>a = [10, 5.5, 'python']<br /> &nbsp;<br /> print(a)<br /> &nbsp;<br /> a = [5,10,15,20,25,30,35,40]<br /> &nbsp;<br /> # a[2] = 15<br /> print(&quot;a[2] = &quot;, a[2])<br /> &nbsp;<br /> # a[0:3] = [5, 10, 15]<br /> print(&quot;a[0:3] = &quot;, a[0:3])<br /> &nbsp;<br /> # a[5:] = [30, 35, 40]<br /> print(&quot;a[5:] = &quot;, a[5:])</p> <p>The output of the above program is following:</p> <p>[10, 5.5, 'python']<br /> a[2] =&nbsp; 15<br /> a[0:3] =&nbsp; [5, 10, 15]<br /> a[5:] =&nbsp; [30, 35, 40]</p> <p>In the above example, we have used the slicing operator [] to extract items or multiple items from a list. In Python, the index form starts at 0.</p> <h3>Tuple Data Type</h3> <p>In python programming, a tuples data type is alike to list data type. But it is only one difference, once tuples created can not be changed/modify.</p> <p>Tuples contain the collection of the items of different data types alike list data type. The items of the tuple are separated with a comma (,) and enclosed in parentheses ().</p> <p>For example:</p> <p>a = (8,'python', 1+2j)<br /> &nbsp;<br /> # a[1] = 'program'<br /> print(&quot;a[1] = &quot;, a[1])<br /> &nbsp;<br /> # a[0:3] = (5, 'program', (1+3j))<br /> print(&quot;a[0:3] = &quot;, a[0:3])</p> <p>Output of the above code is following:</p> <p>a[1] =&nbsp; python<br /> a[0:3] =&nbsp; (8, 'python', (1+2j))</p> <h3>Strings Data Type</h3> <p>In python programming, A string is a sequence of characters in Python. In python, Strings are either enclosed with single quotes, double, and triple quotes.</p> <p>Note:- In python, Multi-line strings can be denoted using triple quotes, &rdquo;&rsquo; or &ldquo;&rdquo;&rdquo;.</p> <p>For example:</p> <p>string = 'Hello world!'<br /> &nbsp;<br /> # string[1] = 'e'<br /> print(&quot;string[1] = &quot;, string[1])<br /> &nbsp;<br /> mString = &quot;&quot;&quot;Hello world!<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this is multi&nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line string example&quot;&quot;&quot;<br /> &nbsp;<br /> print(mString)</p> <p>Output of the above code is following:</p> <p>string[1] =&nbsp; e<br /> Hello world!<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this is multi&nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line string example</p> <h3>Set Data Type</h3> <p>In python programming, set data types hold unordered collection of unique items. The items stored in the set data types are separated with a comma (,) and enclosed within square brackets { }.</p> <p>For example:</p> <p>abc = {5,2,3,1,4}<br /> &nbsp;<br /> # printing set variable<br /> print(&quot;abc = &quot;, abc)<br /> &nbsp;<br /> # data type of variable a<br /> print(type(abc))</p> <p>Output of the above code is following:</p> <p>abc =&nbsp; {1, 2, 3, 4, 5}<br /> &lt;class 'set'&gt;</p> <h3>Dictionary Data Type</h3> <p>In python programming, Dictionary data types is held data in key and value pairs.</p> <p>Note:-&nbsp;A dictionary data type does not allow duplicate keys in collection. But the values ??can be duplicate.</p> <p>For example:</p> <p>dict = {1:&quot;john&quot;,&quot;lastname&quot;:&quot;smith&quot;, &quot;age&quot;:25}<br /> &nbsp;<br /> # prints the value where key value is 1<br /> print(dict[1])<br /> &nbsp;<br /> # prints the value where key value is &quot;lastname&quot;<br /> print(dict[&quot;lastname&quot;])<br /> &nbsp;<br /> # prints the value where key value is &quot;age&quot;<br /> print(dict[&quot;age&quot;])</p> <p>Output of the above code is following:</p> <p>john<br /> smith<br /> 25</p> Thu, 02 Jun 2022 08:55:44 +0530http://codinghelptech.com/Python/Python-Data-Types-with-ExamplePython Variable and Type Examplehttp://codinghelptech.com/Python/Python-Variable-and-Type-Example<p>In this python variable and it&rsquo;s type example tutorial. You will learn what is variable in python, what types of variable in python and how to create and use variables in python.</p> <h2>Python Variable and Type with example</h2> <p>Here you will learn how to create/declare variables in python and also you will learn how many types of declaring the variable in python.</p> <p>&nbsp;</p> <h3>What is the variable in python?</h3> <p>Basically a variable in python is nothing, but it only holds the data or any values in it. There is no special command to make it. You can easily change it value on runtime.</p> <p>Before we talk more about python variable and it&rsquo;s types, we should know the important things or rules for creating variables in the python programming language.</p> <h4>Rules for creating a variable in python</h4> <p>Rule 1:&nbsp;A variable name must begin with a letter or the underscore character<br /> Rule 2:&nbsp;A variable name cannot begin with a number<br /> Rule 3:&nbsp;The python variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )<br /> Rule 4:&nbsp;A Variable names are case-sensitive Like name, Name and NAME are three different variables</p> <h3>Python declare/create variable</h3> <p>Here first we will create/declare a variable. And also assign value to it.</p> <p>For example:</p> <pre> x = 10 print(&quot;My fav no is &quot; + x)</pre> <h3>Change variable value in python</h3> <p>We will create a variable and change the value of this variable at runtime.</p> <pre> x = 10 print(&quot;My fav no is &quot; + x) x = 15 print(&quot;My fav no is &quot; + x) </pre> <p>&nbsp;</p> <h3>Assigning a single value to multiple variables</h3> <p>Also Python allows to assign a single value to several variables simultaneously.</p> <p>For example:</p> <pre> x = y = z = 10 print(x) print(y) print(z) </pre> <p>&nbsp;</p> <h3>Assigning a different values to multiple variables</h3> <pre> x, y, z = 5, &quot;string&quot;, 99 print(a) print(b) print(c) </pre> <p>When you create/declare a variable in Python. So you do not need to declare its type. Python itself detects what type of value store in it. Means variable has numbers or is a string or float value is value, etc.</p> <p>Note:-&nbsp;And if you do not assign any value type value to it, then it will throw the exception.</p> <p>For example:</p> <pre> #int value myint = 7 print(myint) #float value myfloat = 7.0 print(myfloat) #string vlaue mystring = &quot;hello&quot; print(mystring) #invalid assigment invalid = 5 + &quot;5&quot; print(invalid)</pre> <h3>How many types of variable in python?</h3> <p>Variables in Python programming are of two types, such as Local &amp; Global Variables.</p> <h4>Local Variable</h4> <p>Which variables are made inside the function. They are called local variables. Local variables can be used only inside the function.</p> <p>For example:</p> <pre> def valfun(): x = &quot;great&quot; print(&quot;Python is &quot; + x) valfun()</pre> <h4>Global Variable</h4> <p>Which variables are made outside the function. They are called global variables. Global variables can be used both inside and outside the function.</p> <p>For example:</p> <pre> x = &quot;great&quot; def valfun(): print(&quot;Python is &quot; + x) valfun()</pre> <h3>Global Keyword</h3> <p>Generally, when you create a variable inside any function, that is local variable. And you can not use this variable outside of the function.</p> <p>You can create/define a global variable inside the function by using the global keyword.</p> <p>For example:</p> <pre> def valfun(): global x x = &quot;powerful&quot; valfun() print(&quot;Python is &quot; + x)</pre> Wed, 01 Jun 2022 08:56:09 +0530http://codinghelptech.com/Python/Python-Variable-and-Type-ExamplePython Statements Indentation and Comments Examplehttp://codinghelptech.com/Python/Python-Statements-Indentation-and-Comments-Example<p>This tutorial, you will learn python statements, indentation and comments with example. You will learn why indentation is important in python programming, why use of comments in python programming.</p> <h2>Python Statements Indentation and Comments Example</h2> <h3>Python Statement</h3> <p>In python programming, A statement is a logical instruction. Which can read and execute by Python interpreter. In Python, it could be an expression or an assignment statement.</p> <h4>Simple Assignment Statement</h4> <p>In a simple assignment statement, Here we will create new variables and assign values. You can see the following example below:</p> <h4>Syntax</h4> <pre> variable = expression</pre> <p>For Example:</p> <p>Let&rsquo;s take the most basic simple assignment in Python programming.</p> <p>&gt;&gt;&gt; lang = &quot;Learn Python&quot;</p> <h4>Multi-line statement</h4> <p>Generally, in python break the statement line is by a newline character. However, we can make a statement extend over multiple lines with the line continuation character ().</p> <p>For Example:</p> <p>x = 5 + 4 + 2 + \<br /> &nbsp; &nbsp; 1 + 6 + 4 + \<br /> &nbsp; &nbsp; 9 + 7 + 8</p> <p>Implicit line continuation in python. When you split a statement using either of parentheses ( ), brackets [ ] and braces { }. You need to enclose the target statement using the mentioned construct.</p> <p>For example</p> <p>x = (5 + 4 + 2 +<br /> &nbsp; &nbsp; 1 + 6 + 4 +<br /> &nbsp; &nbsp; 9 + 7 + 8)</p> <p><span style="font-family:noto sans,helvetica neue,helvetica,arial,sans-serif; font-size:18px">For example</span></p> <p>colors = ['red',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'blue',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'green']</p> <p>If you want to write multiple line statements in signle line. So you can use semicolons for that.</p> <p>For example</p> <p>a = 1; b = 2; c = 3</p> <h3>Python Indentation</h3> <p>C, C++, C#, Java high-level programming languages are used braces { } to mark a block of code. But Python uses indentation.</p> <p>A code block starts with indentation and ends with the first unindented line. And a code block that represents the body of a function, loop, etc.</p> <p>For example:</p> <p>for i in range(1,9):<br /> &nbsp; &nbsp; print(i)<br /> &nbsp; &nbsp; if i == 5:<br /> &nbsp; &nbsp; &nbsp; &nbsp; break</p> <h3>Python Comments</h3> <p>Comment writing is a good programming practice and it&rsquo;s very important part of programming. They are non-executable chunks of line, yet are quite necessary in a program. These not only help other programmers working on the same project. It describes what is happening inside a program so that the person looking at the source code does not have a hard time removing it. but testers can also refer to them for clarity on white-box testing.</p> <p>In Python, you can use (#) symbol to start writing a comment.</p> <h4>Single line comment</h4> <p>You can write single line comments using # in Python.</p> <p>For Example:</p> <p>#This is hello world by tutsmake.com<br /> print('Hello world')</p> <h4>Multi line comment</h4> <p>Also, You can write multi-line comments using # in Python.</p> <p>For Example:</p> <p>#This is hello world program<br /> #by tutsmake.com<br /> #hello<br /> print('Hello world')</p> <p>Second way of doing multi line comments in python programs, so you can use triple quotes, either &rdquo;&rsquo; or &ldquo;&rdquo;&rdquo;.</p> <p>These triple quotes are generally used for multi-line strings. But they can be used as multi-line comment as well.</p> <p>For example</p> <p>&quot;&quot;&quot;This is also a<br /> &nbsp; &nbsp; multi line<br /> &nbsp; &nbsp; comments&quot;&quot;&quot;<br /> print('Hello world')</p> <h4>Docstring in Python</h4> <p>Docstring is short for documentation string.</p> <p>Comments and docstrings give values to a program. They make your programs more readable and maintainable. Even if you need to refactor the same code later, then it would be easier to do with comments available.</p> <p>Triple quotes are used while writing docstrings.</p> <p>For example:</p> <p>def myFunc(no):<br /> &nbsp; &nbsp; &quot;&quot;&quot;Function to 10x the value&quot;&quot;&quot;<br /> &nbsp; &nbsp; return 10*no</p> <p>You can access code above using the following special attribute __doc__ of the function.</p> <p>&gt;&gt;&gt; print(myFunc.__doc__)</p> Mon, 30 May 2022 09:20:21 +0530http://codinghelptech.com/Python/Python-Statements-Indentation-and-Comments-ExamplePython keywords and Identifiers Examplehttp://codinghelptech.com/Python/Python-keywords-and-Identifiers-Example<p>This python programming keywords and identifiers tutorial has main purpose to teach / explain you about the Python keywords and identifiers. They are the basic fundamental of Python programming. So, you must know everything about them.</p> <p>In this python programming tutorial, you will learn python programming keywords and identifiers. The python programming keywords is reserved words in python programming that can not be used as variable, function name etc. And python programming identifiers like names given to variables, functions, etc.</p> <h2>Python keywords and Identifiers With Example</h2> <h3>Python Programming Keywords</h3> <p>The python programming keywords are reserved words. Which is can not be used as the function name, variable name, and any identifier name, etc. Each keyword has a specific meaning. Basically python programming keywords are used to define the syntax and structure of the Python programming language.</p> <p>Note:-&nbsp;In Python, All keywords are case sensitive. Therefore, you should be careful when using them in your code.</p> <div class="wp-container-1 wp-block-group" style="box-sizing: border-box; font-family: &quot;noto sans&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 18px;"> <div class="wp-block-group__inner-container" style="box-sizing: inherit;"> <p>All the keywords except True, False and None are in lowercase and they must be written as it is. The list of all python programming language keywords is given below.</p> </div> </div> <table style="border-collapse:collapse; border-color:rgb(230, 230, 230); border-image:initial; border-spacing:0px; border-style:solid; border-width:1px 0px 0px 1px; box-sizing:inherit; margin:0px 0px 1.75rem; table-layout:fixed; width:780px"> <tbody> <tr> <td style="border-color:transparent"><code>False</code></td> <td style="border-color:transparent"><code>class</code></td> <td style="border-color:transparent"><code>finally</code></td> <td style="border-color:transparent"><code>is</code></td> <td style="border-color:transparent"><code>return</code></td> </tr> <tr> <td style="border-color:transparent"><code>None</code></td> <td style="border-color:transparent"><code>continue</code></td> <td style="border-color:transparent"><code>for</code></td> <td style="border-color:transparent"><code>lambda</code></td> <td style="border-color:transparent"><code>try</code></td> </tr> <tr> <td style="border-color:transparent"><code>True</code></td> <td style="border-color:transparent"><code>def</code></td> <td style="border-color:transparent"><code>from</code></td> <td style="border-color:transparent"><code>nonlocal</code></td> <td style="border-color:transparent"><code>while</code></td> </tr> <tr> <td style="border-color:transparent"><code>and</code></td> <td style="border-color:transparent"><code>del</code></td> <td style="border-color:transparent"><code>global</code></td> <td style="border-color:transparent"><code>not</code></td> <td style="border-color:transparent"><code>with</code></td> </tr> <tr> <td style="border-color:transparent"><code>as</code></td> <td style="border-color:transparent"><code>elif</code></td> <td style="border-color:transparent"><code>if</code></td> <td style="border-color:transparent"><code>or</code></td> <td style="border-color:transparent"><code>yield</code></td> </tr> <tr> <td style="border-color:transparent"><code>assert</code></td> <td style="border-color:transparent"><code>else</code></td> <td style="border-color:transparent"><code>import</code></td> <td style="border-color:transparent"><code>pass</code></td> <td style="border-color:transparent">&nbsp;</td> </tr> <tr> <td style="border-color:transparent"><code>break</code></td> <td style="border-color:transparent"><code>except</code></td> <td style="border-color:transparent"><code>in</code></td> <td style="border-color:transparent"><code>raise</code></td> </tr> </tbody> </table> <h4>Create a program to test Keywords Is Valid or not.</h4> <p>You can test whether a Python Keywords is valid or not by using the keyword.iskeyword() function. It will returns &ldquo;True&rdquo; if the keyword is correct. Otherwise it will return &ldquo;False&rdquo;.</p> <p>Use the below snippet.</p> <p>&gt;&gt;&gt; import keyword<br /> &gt;&gt;&gt; keyword.iskeyword(&quot;tutsmake.com&quot;)<br /> False<br /> &gt;&gt;&gt; keyword.iskeyword(&quot;try&quot;)<br /> True<br /> &gt;&gt;&gt;</p> <h3>Python Programming identifiers</h3> <p>In the Python programming language, identifiers are user-defined names. Which represents functions, classes, variables, and any other objects in the code. It helps to distinguish one identity from another.</p> <p>For example: &ndash; If you give some name to a programmable entity in Python programming language, it is nothing but technically called an identifier in Python programming language.</p> <p>There are some rules for writing identifiers in Python programming language. When you write Identifiers in Python. At that time you have to take care of some rules.</p> <p>You can see the identifier rules of Python programming language below.</p> <p>Rule 1:&nbsp;To write an identifier in python programming, use either a lowercase (A to Z) or an uppercase (A to Z) sequence of letters. However, you can also add digits (0 to 9) or an underscore (_) while writing identity in python.</p> <p>For example:-&nbsp;Names like myClass, my_1, and upload_image_to_db are all valid identifiers.</p> <p>Rule 2:&nbsp;You cannot write digit with the start of an identifier. This will assume invalid. But you can write digit with the end of the identifier.</p> <p>For Example:-&nbsp;If you write identifier like 1variable, it is invalid, but variable1 is perfectly fine.</p> <p>Rule 3:&nbsp;Python Programming Reserved Keywords cannot be used as identifiers. Like del, global, not, with, as, if, etc.</p> <p>For Example</p> <p>&gt;&gt;&gt; if = 1<br /> &nbsp; File &quot;&lt;interactive input&gt;&quot;, line 1<br /> &nbsp; &nbsp; if = 1<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^<br /> SyntaxError: invalid syntax</p> <p>Rule 4: Also, you can not use special character as an identifier in python programming like &lsquo;.&rsquo;, &lsquo;!&rsquo;, &lsquo;@&rsquo;, &lsquo;#&rsquo;, &lsquo;$&rsquo;, &lsquo;%&rsquo; , etc.</p> <p>&gt;&gt;&gt; b$ = 0<br /> &nbsp; File &quot;&lt;interactive input&gt;&quot;, line 1<br /> &nbsp; &nbsp; b$ = 0<br /> &nbsp; &nbsp; &nbsp;^<br /> SyntaxError: invalid syntax</p> <p>Rule 5:&nbsp;The identifier can be of any length.</p> <h4>Create a program to test identifier Is Valid or not.</h4> <p>You can test whether a Python identifier is valid or not by using the identifier.isidentifier() function. It will returns &ldquo;True&rdquo; if the identifier is correct. Otherwise it will return &ldquo;False&rdquo;.</p> <p>&gt;&gt;&gt; 'jonh'.isidentifier()<br /> True<br /> &gt;&gt;&gt; '1hello'.isidentifier()<br /> False<br /> &gt;&gt;&gt; 'tutsmake.com'.isidentifier()<br /> False<br /> &gt;&gt;&gt; 'tutsmake_com'.isidentifier()<br /> True</p> Fri, 27 May 2022 08:58:56 +0530http://codinghelptech.com/Python/Python-keywords-and-Identifiers-ExampleInstall Python on Windows, Linux, Machttp://codinghelptech.com/Python/Install-Python-on-Windows-Linux-Mac<p>In this post, we will learn how to install Python in Windows, Linux, and Mac systems.</p> <p>We will find the easiest way to run Python and also run first hello-world program on your computer (Windows, Mac OS X or Linux) in this post.</p> <h2>Install Python</h2> <ul> <li>Install and Run Python in Mac OS X</li> <li>Install and Run Python in Linux (Ubuntu)</li> <li>Install and Run Python in Windows</li> </ul> <h3>1. Install and Run Python in Mac OS X</h3> <p>Follow the steps given below and install Python in your Mac OS X system:</p> <ol> <li>Go to Download https://www.python.org/, python official website and Download Python lastest version. Because you may see different version on python.org.</li> <li>When Python is fully downloaded, open the package and follow the instructions. You will see the &ldquo;Installation was successful&rdquo; message when Python is successfully installed.</li> <li>After this, download a good text editor in your system. Such as Sublime text editor, visual text editor, pycharm text editor and as you want</li> </ol> <h3>2. Install and Run Python in Linux (Ubuntu)</h3> <p>Follow the steps given below and install Python in your Linux (Ubuntu) system:</p> <ol> <li>Go to your command prompt and update dependencies, so use the following command to update dependencies in your system:</li> <li>apt-get&nbsp;update</li> <li>After that,&nbsp;Install Python&nbsp;in your system. So use the following command to install python in your linux system:</li> <li>apt-get&nbsp;install&nbsp;python 3.9</li> <li>After this, download a good text editor in your system. Such as Sublime text editor, visual text editor, pycharm text editor and as you want</li> </ol> <h3>3. Install and Run Python in Windows</h3> <p>Follow the steps given below and install Python in your Windows system:</p> <ol> <li>Go to Download https://www.python.org/, python official website and Download Python lastest version. Because you may see different version on python.org.</li> <li>Next double-click on the downloaded file and follow the instructions to install it. When it successfully install. You will see the &ldquo;Installation was successful&rdquo; message when Python is successfully installed.</li> <li>After this, download a good text editor in your system. Such as Sublime text editor, visual text editor, pycharm text editor and as you want</li> </ol> <p>Once you have installed Python in your system successfully. After this, we will create the first program Hello World.</p> <p>For this, whatever you have installed / downloaded your text editor. Open it and follow the instruction given below.</p> <h2>Create first Hello world program in python</h2> <h3>Step1: Open your text editor</h3> <p>In this step, open your text editor and create a new file name hello.py</p> <h3>Step2: Update the code into hello.py</h3> <p>Next, update the following hello world program code into your hello.py file:</p> <p>print('hello world')</p> <h3>Step3: Open command prompt</h3> <p>In this step, we will run the hello.py file using the following python command:</p> <p>For example C:\Users\<em>Your Name</em>&gt;python hello.py</p> <pre> python hello.py</pre> <h5>Output</h5> <p>You will see the output of hello world program on your command prompt (CLI OR CMD):</p> <div class="wp-container-1 wp-block-group has-pale-cyan-blue-background-color has-background" style="box-sizing: border-box; font-family: &quot;noto sans&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 18px; background-color: var(--wp--preset--color--pale-cyan-blue) !important;"> <div class="wp-block-group__inner-container" style="box-sizing: inherit;"> <pre> Hello, World!</pre> </div> </div> Mon, 23 May 2022 08:42:57 +0530http://codinghelptech.com/Python/Install-Python-on-Windows-Linux-MacPython Programming Language Introductionhttp://codinghelptech.com/Python/Python-Programming-Language-Introduction<h2>Introduction Python Programming Language</h2> <p>In this post, we would love to share with you introduction of python programming language and what can python programming do? etc.</p> <h3>What is python programming language?</h3> <div class="wp-container-1 wp-block-group has-background" style="box-sizing: border-box; font-family: &quot;noto sans&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 18px; background-color: rgb(0, 209, 115);"> <div class="wp-block-group__inner-container" style="box-sizing: inherit;"> <p>Python Programming is a powerful multi purpose programming language. This is created by Guido van Rossum. Python is a high-level programming language. which is used for web development (server-side), software development, mathematics, system scripting, etc.The design began in the late 1980s and was first released in February 1991.</p> </div> </div> <h3>History of Python</h3> <div class="wp-container-2 wp-block-group has-luminous-vivid-amber-background-color has-background" style="box-sizing: border-box; font-family: &quot;noto sans&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 18px; background-color: var(--wp--preset--color--luminous-vivid-amber) !important;"> <div class="wp-block-group__inner-container" style="box-sizing: inherit;"> <p>Python Programming is created by Guido van Rossum. The design began in the late 1980s and was first released in February 1991.</p> </div> </div> <h4>Why the name Python?</h4> <p>It was not named after a dangerous snake. Rosum was a fan of a comedy series since the late seventies. The name &ldquo;Python&rdquo; was adopted from the same series &ldquo;Monty Python Flying Circus&rdquo;.</p> <h4>Why Python was created?</h4> <p>In the late 1980s, Guido Van Rossum was working on the Amoeba Distributed Operating Systems Group. He wanted to use an interpreted language like ABC (ABC has simple easy-to-understand syntax) that can access amoeba system calls. Therefore, they decided to create a language that was extensible. This led to the design of a new language, later named Python.</p> <h3>Features of Python Programming</h3> <div class="wp-container-3 wp-block-group has-pale-cyan-blue-background-color has-background" style="box-sizing: border-box; font-family: &quot;noto sans&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 18px; background-color: var(--wp--preset--color--pale-cyan-blue) !important;"> <div class="wp-block-group__inner-container" style="box-sizing: inherit;"> <ul> <li><span style="font-size:14px">A simple programming language which is easier to learn</span></li> <li><span style="font-size:14px">Free and open-source</span></li> <li><span style="font-size:14px">Portability</span></li> <li><span style="font-size:14px">Extensible and Embeddable</span></li> <li><span style="font-size:14px">A high-level, interpreted language</span></li> <li><span style="font-size:14px">Large standard libraries to solve common tasks</span></li> <li><span style="font-size:14px">Object-oriented</span></li> </ul> </div> </div> <h3>What can Python programming language do?</h3> <div class="wp-container-4 wp-block-group has-very-light-gray-background-color has-background" style="box-sizing: border-box; background-color: rgb(238, 238, 238); font-family: &quot;noto sans&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 18px;"> <div class="wp-block-group__inner-container" style="box-sizing: inherit;"> <ul> <li><span style="font-size:14px">Python Programming language can be used alongside software to create workflows.</span></li> <li><span style="font-size:14px">Python Programming language can be used on a server to create web applications.</span></li> <li><span style="font-size:14px">Python Programming language can connect to database systems. It can also read and modify files.</span></li> <li><span style="font-size:14px">Python Programming language can be used to handle big data and perform complex mathematics.</span></li> <li><span style="font-size:14px">Python Programming language can be used for rapid prototyping, or for production-ready software development.</span></li> </ul> </div> </div> Fri, 20 May 2022 07:44:08 +0530http://codinghelptech.com/Python/Python-Programming-Language-IntroductionSet Static IP Address on Ubuntu 22.04 Command Linehttp://codinghelptech.com/Tips-Tricks/Set-Static-IP-Address-on-Ubuntu-2204-Command-Line<p>Ubuntu set static ip address using command line; Through this tutorial, we will learn how to set static ip address on linux ubuntu 22.04 system using command line or prompt.</p> <h2>Ubuntu Set Static IP Address Using Command Line</h2> <p>Use the following steps to set static ip address using command line; is as follows:</p> <ul> <li>Step 1 &ndash; Check device name</li> <li>Step 2 &ndash; Create a Static connection</li> <li>Step 3 &ndash; Add DNS IP to static-ip</li> <li>Step 4 &ndash; Activate the Static connection</li> <li>Step 5 &ndash; Verify the IP assignment to the selected device</li> </ul> <h3>Step 1 &ndash; Check device name</h3> <p>First of all open terminal or command line to check device name by using the following command:</p> <pre> nmcli connection show</pre> <p>The given output shows that our device name is &ldquo;emp0s3&rdquo;:</p> <h3>Step 2 &ndash; Create a Static connection</h3> <p>Use the following command to create&nbsp;a&nbsp;new static&nbsp;connection named &ldquo;static ip&rdquo; for the &ldquo;emp0s3&rdquo; device:</p> <pre> $ sudo nmcli con add type ethernet con-name 'static-ip' ifname emp0s3 ipv4.method manual ipv4.addresses 192.168.1.102/24 gw4 192.168.1.1 </pre> <h3>Step 3 &ndash; Add DNS IP to static-ip</h3> <p>Execute the following command to add the DNS IP to the &ldquo;static-ip&rdquo; connection:</p> <pre> sudo nmcli con mod static-ip ipv4.dns 192.168.1.1</pre> <h3>Step 4 &ndash; Activate the Static connection</h3> <p>Execute the following command on command lien to active &ldquo;static-ip&rdquo;&nbsp;connection:</p> <pre> sudo nmcli con up id 'static-ip'</pre> <h3>Step 5 &ndash; Verify the IP assignment to the selected device</h3> <p>Now, execute the &ldquo;ip&rdquo; command with the &ldquo;a&rdquo; option to validate the IP assigned to the &ldquo;enp0s3&rdquo; device:</p> <pre> ip a</pre> <p>Then, verify the internet connectivity with the help of the following &ldquo;ping&rdquo; command:</p> <pre> <em>&nbsp;</em>ping&nbsp;google.com</pre> <h2>Conclusion</h2> <p>Through this tutorial, we have learned how to set a static IP address on Linux ubuntu 22.04 system using the command line or prompt.</p> Thu, 19 May 2022 09:12:02 +0530http://codinghelptech.com/Tips-Tricks/Set-Static-IP-Address-on-Ubuntu-2204-Command-LineLaravel 9 Create Custom Helper Functions Examplehttp://codinghelptech.com/Php/Laravel-9-Create-Custom-Helper-Functions-Example<p>Laravel 9 custom helper with functions; In this tutorial, we will learn how to create and use a custom helper in laravel 9 apps. And how to call the helper function in laravel 9 on blade view, controller, and model files.</p> <p>Note that, Laravel 9 custom helper helps to reduce the re-writing the same code again and again. In this custom helper tutorial, we will show an example of how we can create a function in custom helper and how to call this function.</p> <h2>Laravel 9 Create Custom Helper Functions Example</h2> <p>Use the following steps to create and use custom helper functions in laravel 9 apps:</p> <ul> <li>1 &ndash; Create helpers.php File</li> <li>2. Add File Path In composer.json File</li> <li>3 &ndash; Run Command for autoloading</li> </ul> <h3>1 &ndash; Create helpers.php File</h3> <p>In this step, we need create helpers.php in the laravel project inside the app directory.</p> <p>In this file, we can write our own custom functions and call anywhere in laravel blade view, controller and model file.</p> <p>For example, we can create a following functions in custom helpers.php file:</p> <p>&lt;?php<br /> &nbsp; function random_code(){<br /> &nbsp; &nbsp; return rand(1111, 9999);<br /> &nbsp; }<br /> &nbsp;<br /> &nbsp; function allUpper($str){<br /> &nbsp; &nbsp; return strtoupper($str);<br /> &nbsp; }</p> <h3>2. Add File Path In composer.json File</h3> <p>In this second step, we will add the path of the helpers file in the composer.json file. Let&rsquo;s go to project root directory and open composer.json file and update the below-given code into the file:</p> <p>composer.json</p> <p>&quot;autoload&quot;: {<br /> &nbsp; &nbsp; &quot;psr-4&quot;: {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &quot;App\\&quot;: &quot;app/&quot;,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &quot;Database\\Factories\\&quot;: &quot;database/factories/&quot;,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &quot;Database\\Seeders\\&quot;: &quot;database/seeders/&quot;<br /> &nbsp; &nbsp; },<br /> &nbsp; &nbsp; &nbsp; &nbsp;&quot;files&quot;: [<br /> &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &quot;app/helpers.php&quot;<br /> &nbsp;<br /> &nbsp; &nbsp; ]<br /> },</p> <h3>3 &ndash; Run Command for autoloading</h3> <p>In this final step, go to the command prompt and type the given command:</p> <pre> composer dump-autoload</pre> <p>After run the above command on command prompt. Then we can use custom helper functions by calling this functions name.</p> <h2>How to use helper function in laravel</h2> <p>Now, we will learn how to call or use above created custom helper function in laravel by examples:</p> <h3>1 &ndash; How to call helper function in laravel blade</h3> <p>We can see the following example of how to call helper function in laravel blade view file:</p> <p>&lt;h2&gt;&lt;?php echo allUpper('I am from tutsmake.com') ?&gt;&lt;/h2&gt;</p> <h3>2 &ndash; How to call helper function in laravel controller</h3> <p>We can see the following example of how to call helper function in laravel controller file:</p> <p>public function index()<br /> {&nbsp; &nbsp;<br /> &nbsp; &nbsp; $data['title'] = allUpper('Title');<br /> &nbsp; &nbsp; return view('view', $data);<br /> }</p> <h2>Conclusion</h2> <p>In this tutorial, we have learned how to create helper and functions in laravel And as well as how to use/call helper functions in laravel on blade view, controller file.</p> Wed, 18 May 2022 09:16:02 +0530http://codinghelptech.com/Php/Laravel-9-Create-Custom-Helper-Functions-ExampleHow to Find/Get Public IP Windowshttp://codinghelptech.com/Tips-Tricks/How-to-FindGet-Public-IP-Windows<p>Find or get public or private ip from command line windows; Through this tutorial, we will learn how to find or get the public or private ip address of windows using the command line and network file.</p> <p>An IP (Internal Protocol) address is a unique identifier that identifies a device on the internet-connected to the TCP/IP protocol and enabled communication over it. One of the most common and popular examples of a network built on IP addresses is World Wide Web and Internet.</p> <p>For IPv4, its format can be 4 octets like&nbsp;<code>x.x.x.x</code>&nbsp;where each octet is 8 bits or 0 to 255 in decimal. Eg.&nbsp;<code>201.112.192.230</code>.&nbsp;IPv6 addresses&nbsp;support a much larger range and are formatted like&nbsp;<code>y:y:y:y:y:y:y:y</code>&nbsp;where each y is a segment that can range between 0 and FFFF in hexadecimal like&nbsp;<code>2001:0db8:0001:0000:0000:0ab9:C0A8:0102</code>.</p> <p>An IP address&nbsp;helps in location addressing of the connected device and for network interface identification.</p> <h2>How to Get Public IP Address of Windows</h2> <p>There are two following ways to find or get public or private ip address of windows using command line and network file; is as follows:</p> <ul> <li>Solution 1 &ndash; Find Public IP Address Windows using Command Prompt</li> <li>Solution 2 &ndash; Find Public IP Address Windows using Network and Sharing Center</li> </ul> <h3>Solution 1 &ndash; Find Public IP Address Windows using Command Prompt</h3> <p>Open terminal and execute the following command on command prompt to find or get public or private ip address of windows using command line; is as follow:</p> <pre> ipconfig</pre> <p>Then, will see on command prompt; as follow:</p> <p><img alt="" class="lazy-loaded wp-image-19104" src="https://www.tutsmake.com/wp-content/uploads/2022/05/Command-Prompt-ip-address-windows-1024x573.jpg" style="border-radius:inherit; box-sizing:inherit; max-width:100%; vertical-align:bottom; width:700px" /></p> <h3>Solution 2 &ndash; Find Public IP Address Windows using Network and Sharing Center</h3> <p>To find system&rsquo;s/network adapter&rsquo;s IP address is by opening&nbsp;<code>Network and Sharing Center</code>.</p> <p>Open the Control Panel and go to&nbsp;<code>Network and Internet</code>&nbsp;-&gt;&nbsp;<code>Network and Sharing Center</code>&nbsp;-&gt;&nbsp;<code>Connections: &lt;Wi-Fi&gt;/&lt;Ethernet&gt;</code>&nbsp;-&gt;&nbsp;<code>Details</code>.</p> <p><img alt="" class="lazy-loaded wp-image-19105" src="https://www.tutsmake.com/wp-content/uploads/2022/05/Network-Connection-Details-ip-address-windows.jpg" style="border-radius:inherit; box-sizing:inherit; max-width:100%; vertical-align:bottom; width:362px" /></p> Mon, 16 May 2022 10:00:41 +0530http://codinghelptech.com/Tips-Tricks/How-to-FindGet-Public-IP-WindowsLaravel 9 Create Multi Language Website Example Tutorialhttp://codinghelptech.com/Php/Laravel-9-Create-Multi-Language-Website-Example-Tutorial<p>Create mutli language website in laravel 9 apps; Through this tutorial, we will learn how to create multi language website in laravel 9 apps.</p> <h2>Laravel 9 Create Multi Language Website Example Tutorial</h2> <p>Follow the following steps to create multi language website in laravel 9 apps:</p> <ul> <li>Step 1 &ndash; Install Laravel</li> <li>Step 2 &ndash; Create Lang Files</li> <li>Step 3 &ndash; Create Routes</li> <li>Step 4 &ndash; Create LangController Controller</li> <li>Step 5 &ndash; Create View</li> <li>Step 6 &ndash; Create Middleware</li> <li>Step 7 &ndash; Start Laravel App</li> </ul> <h3>Step 1 &ndash; Install Laravel</h3> <p>Execute the following command on command prompt to install laravel app in your system:</p> <pre> composer create-project laravel/laravel example-app </pre> <h3>Step 2 &ndash; Create Lang Files</h3> <p>Create the following folders and files for english, france and spanish language files in lang folder; is as follows:</p> <p>resources/lang/en/messages.php</p> <pre> &lt;?php return [ 'title' =&gt; 'This is English Language Title.', ];</pre> <p>resources/lang/fr/messages.php</p> <pre> &lt;?php return [ 'title' =&gt; 'Ceci est le titre fr langue anglaise.', ];</pre> <p>resources/lang/sp/messages.php</p> <pre> &lt;?php return [ 'title' =&gt; &quot;Il s'agit du titre en langue espagnole.&quot;, ];</pre> <h3>Step 3 &ndash; Create Routes</h3> <p>Visit the routes directory and open web.php. Then create two routes one for displaying the dashboard page with language dropdown and another for you can change language logic; is as follows:</p> <p>&lt;?php<br /> use Illuminate\Support\Facades\Route;<br /> use App\Http\Controllers\LangController;<br /> /*<br /> &nbsp;<br /> |--------------------------------------------------------------------------<br /> &nbsp;<br /> | Web Routes<br /> &nbsp;<br /> |--------------------------------------------------------------------------<br /> &nbsp;<br /> |<br /> &nbsp;<br /> | Here is where you can register web routes for your application. These<br /> &nbsp;<br /> | routes are loaded by the RouteServiceProvider within a group which<br /> &nbsp;<br /> | contains the &quot;web&quot; middleware group. Now create something great!<br /> &nbsp;<br /> |<br /> &nbsp;<br /> */<br /> Route::get('lang/home', [LangController::class, 'index']);<br /> &nbsp;<br /> Route::get('lang/change', [LangController::class, 'change'])-&gt;name('changeLang');</p> <h3>Step 4 &ndash; Create LangController Controller</h3> <p>Execute the following command on command prompt to create LangController file:</p> <pre> php artisan make:controller LangController</pre> <p>Then visit app/http/controllers directorya and open LangController.php file. Then add the following code into it:</p> <p>&lt;?php<br /> namespace App\Http\Controllers;<br /> use Illuminate\Http\Request;<br /> use App;<br /> class LangController extends Controller<br /> {<br /> &nbsp; &nbsp; /**<br /> &nbsp; &nbsp; &nbsp;* Display a listing of the resource.<br /> &nbsp; &nbsp; &nbsp;*<br /> &nbsp; &nbsp; &nbsp;* @return \Illuminate\Http\Response&nbsp;<br /> &nbsp; &nbsp; */<br /> &nbsp; &nbsp; public function index()<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; return view('lang');<br /> &nbsp; &nbsp; }<br /> &nbsp; &nbsp; /**<br /> &nbsp; &nbsp; &nbsp;* Display a listing of the resource.<br /> &nbsp; &nbsp; &nbsp;*<br /> &nbsp; &nbsp; &nbsp;* @return \Illuminate\Http\Response<br /> &nbsp; &nbsp; */<br /> &nbsp; &nbsp; public function change(Request $request)<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; App::setLocale($request-&gt;lang);<br /> &nbsp; &nbsp; &nbsp; &nbsp; session()-&gt;put('locale', $request-&gt;lang);<br /> &nbsp; &nbsp; &nbsp; &nbsp; return redirect()-&gt;back();<br /> &nbsp; &nbsp; }<br /> }</p> <h3>Step 5 &ndash; Create View</h3> <p>Visit resources/views directory and create lang.blade.php file. And add the following code into lang.blade.php file:</p> <p>&lt;!DOCTYPE html&gt;<br /> &nbsp;<br /> &lt;html&gt;<br /> &nbsp;<br /> &lt;head&gt;<br /> &nbsp;<br /> &nbsp; &nbsp; &lt;title&gt;How to Create Multi Language Website in Laravel - Tutsmake.com&lt;/title&gt;<br /> &nbsp;<br /> &nbsp; &nbsp; &lt;meta charset=&quot;utf-8&quot;&gt;<br /> &nbsp;<br /> &nbsp; &nbsp; &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;<br /> &nbsp;<br /> &nbsp; &nbsp; &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;<br /> &nbsp;<br /> &nbsp; &nbsp; &lt;link href=&quot;//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot;&gt;<br /> &nbsp;<br /> &nbsp; &nbsp; &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;<br /> &nbsp;<br /> &lt;/head&gt;<br /> &nbsp;<br /> &lt;body&gt;<br /> &nbsp; &nbsp; &lt;div class=&quot;container&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;h1&gt;How to Create Multi Language Website in Laravel - Tutsmake.com&lt;/h1&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;row&quot;&gt;<br /> &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;col-md-2 col-md-offset-6 text-right&quot;&gt;<br /> &nbsp;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;strong&gt;Select Language: &lt;/strong&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class=&quot;col-md-4&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;select class=&quot;form-control changeLang&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value=&quot;en&quot; {{ session()-&gt;get('locale') == 'en' ? 'selected' : '' }}&gt;English&lt;/option&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value=&quot;fr&quot; {{ session()-&gt;get('locale') == 'fr' ? 'selected' : '' }}&gt;France&lt;/option&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;option value=&quot;sp&quot; {{ session()-&gt;get('locale') == 'sp' ? 'selected' : '' }}&gt;Spanish&lt;/option&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/select&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;h1&gt;{{ __('messages.title') }}&lt;/h1&gt;<br /> &nbsp; &nbsp; &lt;/div&gt;<br /> &lt;/body&gt;<br /> &lt;script type=&quot;text/javascript&quot;&gt;<br /> &nbsp; &nbsp; var url = &quot;{{ route('changeLang') }}&quot;;<br /> &nbsp; &nbsp; $(&quot;.changeLang&quot;).change(function(){<br /> &nbsp; &nbsp; &nbsp; &nbsp; window.location.href = url + &quot;?lang=&quot;+ $(this).val();<br /> &nbsp; &nbsp; });<br /> &lt;/script&gt;<br /> &nbsp;<br /> &lt;/html&gt;</p> <h3>Step 6 &ndash; Create Middleware</h3> <p>Execute the following command on command prompt to create one middleware that will manage dynamic language that we selected on dropdown; is as follow:</p> <pre> php artisan make:middleware LanguageManager</pre> <p>Then visit&nbsp;app/Http/Middleware/&nbsp;directory and open LanguageManager.php&nbsp;file. And add the following code into it:</p> <p>&lt;?php<br /> namespace App\Http\Middleware;<br /> use Closure;<br /> use App;<br /> class LanguageManager<br /> {<br /> &nbsp; &nbsp; /**<br /> &nbsp; &nbsp; &nbsp;* Handle an incoming request.<br /> &nbsp; &nbsp; &nbsp;*<br /> &nbsp; &nbsp; &nbsp;* @param&nbsp; \Illuminate\Http\Request&nbsp; $request<br /> &nbsp; &nbsp; &nbsp;* @param&nbsp; \Closure&nbsp; $next<br /> &nbsp; &nbsp; &nbsp;* @return mixed<br /> &nbsp; &nbsp; &nbsp;*/<br /> &nbsp; &nbsp; public function handle($request, Closure $next)<br /> &nbsp; &nbsp; {<br /> &nbsp; &nbsp; &nbsp; &nbsp; if (session()-&gt;has('locale')) {<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; App::setLocale(session()-&gt;get('locale'));<br /> &nbsp; &nbsp; &nbsp; &nbsp; }<br /> &nbsp; &nbsp; &nbsp; &nbsp; return $next($request);<br /> &nbsp; &nbsp; }<br /> }</p> <p>Then visit app/Http/ directory and open Kernel.php file. And register middleware; is as follows:</p> <p>&lt;?php&nbsp;<br /> namespace App\Http;<br /> use Illuminate\Foundation\Http\Kernel as HttpKernel;<br /> class Kernel extends HttpKernel<br /> {<br /> &nbsp; &nbsp; /**<br /> &nbsp;<br /> &nbsp; &nbsp; &nbsp;* The application's route middleware groups.<br /> &nbsp;<br /> &nbsp; &nbsp; &nbsp;*<br /> &nbsp;<br /> &nbsp; &nbsp; &nbsp;* @var array<br /> &nbsp;<br /> &nbsp; &nbsp; &nbsp;*/<br /> &nbsp; &nbsp; protected $middlewareGroups = [<br /> &nbsp; &nbsp; &nbsp; &nbsp; 'web' =&gt; [<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \App\Http\Middleware\EncryptCookies::class,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \Illuminate\Session\Middleware\StartSession::class,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \Illuminate\View\Middleware\ShareErrorsFromSession::class,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \App\Http\Middleware\VerifyCsrfToken::class,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \Illuminate\Routing\Middleware\SubstituteBindings::class,<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \App\Http\Middleware\LanguageManager::class,<br /> &nbsp; &nbsp; &nbsp; &nbsp; ],<br /> &nbsp; &nbsp; &nbsp; &nbsp; 'api' =&gt; [<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'throttle:60,1',<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \Illuminate\Routing\Middleware\SubstituteBindings::class,<br /> &nbsp; &nbsp; &nbsp; &nbsp; ],<br /> &nbsp; &nbsp; ];</p> <h3>Step 7 &ndash; Start Laravel App</h3> <p>Execute the following command on command prompt to start larave app; is as follows:</p> <pre> php artisan serve</pre> Fri, 13 May 2022 08:17:46 +0530http://codinghelptech.com/Php/Laravel-9-Create-Multi-Language-Website-Example-Tutorial