<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Talha Maqsood on Medium]]></title>
        <description><![CDATA[Stories by Talha Maqsood on Medium]]></description>
        <link>https://medium.com/@itztalhaa?source=rss-be15e107652e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ThHbJXU99L58Hgk7111leQ.jpeg</url>
            <title>Stories by Talha Maqsood on Medium</title>
            <link>https://medium.com/@itztalhaa?source=rss-be15e107652e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 01:48:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@itztalhaa/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Custom Error Class and Centralized Error Handling in NodeJS]]></title>
            <link>https://itztalhaa.medium.com/custom-error-class-and-centralized-error-handling-in-nodejs-03887eb65793?source=rss-be15e107652e------2</link>
            <guid isPermaLink="false">https://medium.com/p/03887eb65793</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[node-js-tutorial]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <dc:creator><![CDATA[Talha Maqsood]]></dc:creator>
            <pubDate>Mon, 02 Dec 2024 10:54:23 GMT</pubDate>
            <atom:updated>2024-12-02T10:54:23.215Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TkiJTvYRrK1KXY1UvXDfWw.png" /><figcaption>ThrowError</figcaption></figure><p>When building APIs, handling errors gracefully is crucial for maintaining a clean codebase and providing meaningful feedback to the client. Without a proper error-handling mechanism, it becomes difficult to distinguish between different types of errors, especially when each error needs to return a specific HTTP status code.</p><p>For example, a validation error should return a 400 (Bad Request), while an authorization issue requires a 401 (Unauthorized). If you rely on generic error messages, your application might end up sending the wrong status codes, leading to confusion for both developers and clients.</p><p>Here is an example of how most of people handles errors and send response.</p><pre>exports.findAUser = async (req, res) =&gt; {<br>    try {<br><br>        const {id} = req.params;<br><br>        let user = await User.findById(id);<br><br>        if (!user) {<br>            // send error in API<br>            res.status(404).send(&quot;User not found&quot;);<br>        }<br><br>        // send success with user data<br>        res.status(200).json(user);<br>    } catch (err) {<br>        // send error in API<br>        res.status(500).send(err.message);<br>    }<br>}</pre><p>There is no potential issue in this code snippet but we can improve the error handling here.</p><p>So, my solution is to make a <strong>Custom Error Class</strong> to throw all errors in catch with HTTP status code and data. I will use catch to send error response in API and we can also make 2 helpers for success and error to send response in API.</p><p>Let’s make a ThrowErrorclass in NodeJS that extends the built-in Error class. It provides a structured way to handle errors by attaching additional properties such as statusCode and data.</p><pre>class ThrowError extends Error {<br>    constructor(msg = &#39;Something went wrong&#39;, statusCode = 400, data = {}) {<br>        super(msg);<br>        this.statusCode = statusCode;<br>        this.data = data;<br>    }<br>}<br><br>module.exports = ThrowError;</pre><h4><strong>Class Explanation:</strong></h4><p>By extending Error, the ThrowError class inherits all standard error properties and behaviors, such as the message and stack. This makes it compatible with existing error-handling mechanisms in Node.js.</p><p>The constructor provides default values:</p><ul><li>msg: Defaults to &quot;Something went wrong&quot; if no custom message is passed.</li><li>statusCode: Defaults to 400 (Bad Request), a common error code for client-side issues.</li><li>data: Defaults to an empty object {}, allowing developers to attach additional details about the error, such as validation issues or debug information.</li></ul><h4>Usage:</h4><pre>// import the class<br>const ThrowError = require(&#39;@utils/ThrowError&#39;);<br><br>// ...<br>// ...<br><br>let user = await User.findById(id);<br><br>if (!user) {<br>    // send 404 error in API<br>    throw new ThrowError(&#39;User not found&#39;, 404, {id: id});<br>}<br><br>if (!user.isAuthenticated) {<br>    // send 401 error in API<br>    throw new ThrowError(&#39;User not authenticated&#39;, 401, {id: id});<br>}</pre><p>Now, let’s make helpers to send API response</p><pre>const ThrowError = require(&#39;@utils/throwError&#39;);<br><br>const sendSuccessResponse = (response, data = {}, message = &quot;Success&quot;, statusCode = 200) =&gt; {<br>    return response.status(statusCode).json({success: true, message, data});<br>}<br><br>const sendErrorResponse = (response, error) =&gt; {<br>    let statusCode = 400;<br>    if (error instanceof ThrowError) statusCode = error.statusCode;<br>    response.status(statusCode).json({success: false, message: error.message, data: error.data || {}});<br>}<br><br>module.exports = {sendSuccessResponse, sendErrorResponse};</pre><h4>Final Code Block:</h4><p>The code now looks more clean and centralized. This approach will also help to improve debugging.</p><pre>exports.findAUser = async (req, res) =&gt; {<br>    try {<br><br>        const {id} = req.params;<br><br>        let user = await User.findById(id);<br><br>        if (!user) {<br>            throw new ThrowError(&#39;User not found&#39;, 404, {id: id});<br>        }<br><br>        sendSuccessResponse(res, user);<br>    } catch (err) {<br>        sendErrorResponse(res, err);<br>    }<br>}</pre><h4>Benefits of this approach:</h4><ul><li><strong>Attach HTTP Status Codes to Errors</strong><br>A custom error class allows you to define a status code along with the error message. This makes it easy to send accurate responses to the client without additional logic in every catch block.</li><li><strong>Centralize Error Logic</strong><br>Instead of manually setting status codes and messages everywhere, a custom class keeps this logic centralized. This reduces boilerplate code and makes your application easier to maintain.</li><li><strong>Consistent Error Structure</strong><br>Clients consuming your API expect consistent error responses. A custom class ensures that all errors follow the same format, making it easier for developers to debug and for clients to parse.</li><li><strong>Improve Debugging</strong><br>By extending the built-in Error class, you can also include additional metadata such as error types, timestamps, or stack traces, which are invaluable during debugging.</li></ul><p>By leveraging a custom error class, you bring clarity and professionalism to your error-handling strategy, ensuring your APIs are robust, predictable, and easier to work with. This not only makes your development experience smoother but also builds trust with the developers who rely on your API.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03887eb65793" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best Project Structure in NodeJS [MVC]]]></title>
            <link>https://itztalhaa.medium.com/best-project-structure-in-nodejs-mvc-69642d5ef663?source=rss-be15e107652e------2</link>
            <guid isPermaLink="false">https://medium.com/p/69642d5ef663</guid>
            <dc:creator><![CDATA[Talha Maqsood]]></dc:creator>
            <pubDate>Wed, 03 Apr 2024 08:55:49 GMT</pubDate>
            <atom:updated>2024-04-03T08:55:49.089Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FpQjsdtj1nXuEbHgwsprMQ.png" /><figcaption>Folder Structure NodeJS [MVC]</figcaption></figure><p>I am going to make a demo project setup in NodeJS following MVC. So let’s start by creating package.json, Opening the terminal making a new folder, and running “npm init”</p><pre>mkdir test_project<br>cd test_project<br>npm init -y</pre><p>Now, install the necessary packages.</p><blockquote>I’m gonna just setup the project structure so I’m not gonna use any database.</blockquote><pre>npm i cors dotenv express<br>npm i nodemon --save-dev</pre><p>Add a <strong>dev</strong> and <strong>start </strong>the script in the package.json</p><pre>{<br>  &quot;scripts&quot;: {<br>    &quot;dev&quot;: &quot;nodemon index.js&quot;,<br>    &quot;start&quot;: &quot;node index.js&quot;,<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  }<br>}</pre><p>So, the final package.json will look like this</p><pre>{<br>  &quot;name&quot;: &quot;test_project&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;This is just a test project.&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;dev&quot;: &quot;nodemon index.js&quot;,<br>    &quot;start&quot;: &quot;node index.js&quot;,<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;Talha Maqsood&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;cors&quot;: &quot;^2.8.5&quot;,<br>    &quot;dotenv&quot;: &quot;^16.4.5&quot;,<br>    &quot;express&quot;: &quot;^4.19.2&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;nodemon&quot;: &quot;^3.1.0&quot;<br>  }<br>}</pre><p>Now, make .env file for environment variables, I&#39;m gonna add port and cors origins in .env</p><blockquote>Also, make another file .env.sample and copy all the variables from .env but without value. It&#39;s because .env.sample will be pushed to GitHub and it documents the required environment variables and their purpose.</blockquote><pre>PORT=5000<br>CORS_OPTIONS=http://localhost:3000,http://localhost:5000</pre><blockquote><strong>NOTE</strong>: CORS_OPTIONS contains the comma separated domains list so, it can be more flexible for large number of domains</blockquote><p>Make the index.js file to setup cors options and server</p><pre>const express = require(&quot;express&quot;);<br>const cors = require(&#39;cors&#39;);<br>const dotenv = require(&#39;dotenv&#39;);<br><br>const app = express();<br><br>// use .env variables<br>dotenv.config();<br><br>// destructure the cors options from .env to make an array of all domains<br>const CORS_OPTIONS = process.env.CORS_OPTIONS;<br>let corsOrigins = [];<br>if (CORS_OPTIONS) {<br>    corsOrigins = CORS_OPTIONS.split(&#39;,&#39;);<br>}<br><br>// allow cors<br>app.use(cors({<br>    origin: corsOrigins,<br>    optionsSuccessStatus: 200<br>}));<br><br>// make public folder static to server static files<br>app.use(express.static(&#39;public&#39;));<br><br>// parse the request body<br>app.use(express.json());<br>app.use(express.urlencoded({extended: true}));<br><br>app.get(&#39;/&#39;, (req, res) =&gt; {<br>    res.status(200).send(&quot;Server is running!&quot;);<br>});<br><br>// make an express server<br>const PORT = process.env.PORT || 3000;<br>app.listen(PORT, () =&gt; {<br>    console.log(`App is listening on port ${PORT}`);<br>});</pre><p>Now, let&#39;s setup the folder structure.</p><pre>Root<br>    - config<br>        db.js<br>        firebase.js<br>    - public<br>    - src<br>        - controllers<br>            user.controller.js<br>            post.controller.js<br>        - middlewares<br>            auth.middleware.js<br>        - models<br>            user.model.js<br>            post.model.js<br>        - routes<br>            user.route.js<br>            post.route.js<br>            index.route.js<br>        - views<br>            - authentication<br>                login.ejs<br>                signup.ejs<br>    .env<br>    .env.sample<br>    .gitignore<br>    index.js<br>    package.json<br>    package-lock.json</pre><p>Lastly, add .gitignore file if you want to push your code to GitHub. This file includes all the files and folders which we do not want to push to GitHub</p><pre># Logs<br>logs<br>*.log<br>npm-debug.log*<br>yarn-debug.log*<br>yarn-error.log*<br>lerna-debug.log*<br>.pnpm-debug.log*<br><br># Diagnostic reports (https://nodejs.org/api/report.html)<br>report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json<br><br># Runtime data<br>pids<br>*.pid<br>*.seed<br>*.pid.lock<br><br># Directory for instrumented libs generated by jscoverage/JSCover<br>lib-cov<br><br># Coverage directory used by tools like istanbul<br>coverage<br>*.lcov<br><br># nyc test coverage<br>.nyc_output<br><br># Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)<br>.grunt<br><br># Bower dependency directory (https://bower.io/)<br>bower_components<br><br># node-waf configuration<br>.lock-wscript<br><br># Compiled binary addons (https://nodejs.org/api/addons.html)<br>build/Release<br><br># Dependency directories<br>node_modules/<br>jspm_packages/<br><br># Snowpack dependency directory (https://snowpack.dev/)<br>web_modules/<br><br># TypeScript cache<br>*.tsbuildinfo<br><br># Optional npm cache directory<br>.npm<br><br># Optional eslint cache<br>.eslintcache<br><br># Optional stylelint cache<br>.stylelintcache<br><br># Microbundle cache<br>.rpt2_cache/<br>.rts2_cache_cjs/<br>.rts2_cache_es/<br>.rts2_cache_umd/<br><br># Optional REPL history<br>.node_repl_history<br><br># Output of &#39;npm pack&#39;<br>*.tgz<br><br># Yarn Integrity file<br>.yarn-integrity<br><br># dotenv environment variable files<br>.env<br>.env.development.local<br>.env.test.local<br>.env.production.local<br>.env.local<br><br># parcel-bundler cache (https://parceljs.org/)<br>.cache<br>.parcel-cache<br><br># Next.js build output<br>.next<br>out<br><br># Nuxt.js build / generate output<br>.nuxt<br>dist<br><br># Gatsby files<br>.cache/<br># Comment in the public line in if your project uses Gatsby and not Next.js<br># https://nextjs.org/blog/next-9-1#public-directory-support<br># public<br><br># vuepress build output<br>.vuepress/dist<br><br># vuepress v2.x temp and cache directory<br>.temp<br>.cache<br><br># Docusaurus cache and generated files<br>.docusaurus<br><br># Serverless directories<br>.serverless/<br><br># FuseBox cache<br>.fusebox/<br><br># DynamoDB Local files<br>.dynamodb/<br><br># TernJS port file<br>.tern-port<br><br># Stores VSCode versions used for testing VSCode extensions<br>.vscode-test<br><br># yarn v2<br>.yarn/cache<br>.yarn/unplugged<br>.yarn/build-state.yml<br>.yarn/install-state.gz<br>.pnp.*<br><br># github<br>.git<br><br># intelliJ conf<br>.idea</pre><p>This is how I setup my NodeJS project structure depending on the requirements.</p><p><strong>GitHub</strong>: <a href="https://github.com/talhaa99/nodejs-project-setup"><em>https://github.com/talhaa99/nodejs-project-setup</em></a></p><p><em>Hope this might help! 😊</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69642d5ef663" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add Column in Existing Migration Laravel]]></title>
            <link>https://itztalhaa.medium.com/add-column-in-existing-migration-laravel-8c5b5e108056?source=rss-be15e107652e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c5b5e108056</guid>
            <category><![CDATA[larave]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[laravel-framework]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[laravel-migrations]]></category>
            <dc:creator><![CDATA[Talha Maqsood]]></dc:creator>
            <pubDate>Fri, 21 Oct 2022 06:59:02 GMT</pubDate>
            <atom:updated>2022-10-21T07:01:36.859Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, how are you! In this tutorial, I will show how to add columns in existing laravel migration. So, let&#39;s start from the beginning and create a new laravel project.</p><p>GitHub Repo: <a href="https://github.com/talhaa99/add-column-to-existing-migration"><em>add-column-to-existing-migration</em></a></p><pre>composer create-project laravel/laravel project</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*y8HE9uNmPMMw3EcJkb7aIQ.png" /></figure><p>Open this project folder in any code editor. I would recommend using <a href="https://www.jetbrains.com/phpstorm/download/">PhpStorm</a></p><p>Create a new database in MySQL and add your DB credentials in the .env file.</p><pre>DB_CONNECTION=mysql<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=laravel    <strong># your database name</strong><br>DB_USERNAME=root       <strong># your database username</strong><br>DB_PASSWORD=password   <strong># your database password</strong></pre><p>Now, let&#39;s create a product migration, and after I will add another migration to add a column in the products table.</p><pre>php artisan make:migration create_products_table</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*eoxzESUyFZd1fByiT1Vh0g.png" /></figure><pre><strong># Products Table Migration</strong></pre><pre>&lt;?php<br><br>use Illuminate\Database\Migrations\Migration;<br>use Illuminate\Database\Schema\Blueprint;<br>use Illuminate\Support\Facades\Schema;<br><br>return new class extends Migration<br>{<br>    <em>/**<br>     * Run the migrations.<br>     *<br>     * </em><strong><em>@return </em></strong><em>void<br>     */<br>    </em>public function up()<br>    {<br>        Schema::create(&#39;products&#39;, function (Blueprint $table) {<br>            $table-&gt;id();<br>            $table-&gt;string(&#39;name&#39;);<br>            $table-&gt;text(&#39;description&#39;);<br>            $table-&gt;boolean(&#39;is_active&#39;)-&gt;default(false);<br>            $table-&gt;timestamps();<br>        });<br>    }<br><br>    <em>/**<br>     * Reverse the migrations.<br>     *<br>     * </em><strong><em>@return </em></strong><em>void<br>     */<br>    </em>public function down()<br>    {<br>        Schema::dropIfExists(&#39;products&#39;);<br>    }<br>};</pre><p>Now, create another migration to add another column</p><pre>php artisan make:migration add_price_to_products_table</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*axgH_0988iwr_P1tCXzmdg.png" /></figure><pre><strong># Add Price To Products Table Migration</strong></pre><pre>&lt;?php<br><br>use Illuminate\Database\Migrations\Migration;<br>use Illuminate\Database\Schema\Blueprint;<br>use Illuminate\Support\Facades\Schema;<br><br>return new class extends Migration<br>{<br>    <em>/**<br>     * Run the migrations.<br>     *<br>     * </em><strong><em>@return </em></strong><em>void<br>     */<br>    </em>public function up()<br>    {<br>        Schema::table(&#39;products&#39;, function (Blueprint $table) {<br>            $table-&gt;unsignedInteger(&#39;price&#39;)-&gt;after(&#39;is_active&#39;);<br>        });<br>    }<br><br>    <em>/**<br>     * Reverse the migrations.<br>     *<br>     * </em><strong><em>@return </em></strong><em>void<br>     */<br>    </em>public function down()<br>    {<br>        Schema::table(&#39;products&#39;, function (Blueprint $table) {<br>            $table-&gt;dropColumn([&#39;price&#39;]);<br>        });<br>    }<br>};</pre><p>Now, run the migration (migrate all the migrations into MySQL database)</p><pre>php artisan migrate</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*6FFyZ03a-RgoQVPoRm42NA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*uP4_bhmshwHNev3qxN_DZw.png" /><figcaption>Table and columns created in MySQL</figcaption></figure><p><strong>I hope it helps :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c5b5e108056" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Send Random Password To Email On New Registered User In Laravel 9]]></title>
            <link>https://itztalhaa.medium.com/send-random-password-to-email-on-new-registered-user-in-laravel-9-1593326ee519?source=rss-be15e107652e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1593326ee519</guid>
            <category><![CDATA[send-email]]></category>
            <category><![CDATA[laravel-development]]></category>
            <category><![CDATA[random-password-generator]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[send-password-to-email]]></category>
            <dc:creator><![CDATA[Talha Maqsood]]></dc:creator>
            <pubDate>Fri, 29 Jul 2022 12:03:36 GMT</pubDate>
            <atom:updated>2022-07-29T12:13:16.751Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello guys! let’s create a new laravel project</p><p>GitHub Repo: <a href="https://github.com/talhaa99/send-random-password-to-email-laravel.git">send-random-password-to-email-laravel</a></p><pre>composer create-project laravel/laravel SendRandomPass</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*eKzDr4O27LPqpSTwTYBDlQ.png" /><figcaption>Laravel 9 project is created successfully</figcaption></figure><p>Now, open the project folder in any code editor. Recommended IDE is <a href="https://www.jetbrains.com/phpstorm/download/">PhpStorm</a></p><p>Add thedatabase credientials in .env file</p><pre>DB_CONNECTION=mysql<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=laravel # your database name<br>DB_USERNAME=root #your database username<br>DB_PASSWORD=password #your database password</pre><p>Add the mail SMTP details in the .env file. Follow this tutorial to get Gmail SMTP server credentials <a href="https://itztalhaa.medium.com/send-mail-using-gmail-smtp-server-in-laravel-8-9-0-cd317ae6a45a">Send Mail Using Gmail SMTP Server</a>. But I’m using the Mailtrap SMTP server in this tutorial. So, You can follow this tutorial for Mailtrap SMTP <a href="https://itztalhaa.medium.com/config-mailtrap-in-laravel-8-8be3b4abbcb">Config Mailtrap in Laravel 8</a></p><pre>MAIL_DRIVER=smtp<br>MAIL_HOST=smtp.mailtrap.io<br>MAIL_PORT=2525<br>MAIL_USERNAME=abc123... # your mail username<br>MAIL_PASSWORD=abc123... # your mail password<br>MAIL_ENCRYPTION=tls<br>MAIL_FROM_ADDRESS=abc@example.com # your email<br>MAIL_FROM_NAME=&quot;${APP_NAME}&quot;</pre><p>Run this command to migrate all the tables into the MySQL database,</p><pre>php artisan migrate</pre><p>Now make a notification <strong>PasswordToUserEmail.php</strong></p><pre>// Command to make notification<br>php artisan make:notification PasswordToUserEmail</pre><pre>// The notification will be generate in app/Notifications/</pre><p>Write the below code inside PasswordToUserEmail.php</p><pre>&lt;?php</pre><pre>namespace App\Notifications;</pre><pre>use Illuminate\Bus\Queueable;<br>use Illuminate\Contracts\Queue\ShouldQueue;<br>use Illuminate\Notifications\Messages\MailMessage;<br>use Illuminate\Notifications\Notification;</pre><pre>class PasswordToUserEmail extends Notification<br>{<br>    use Queueable;</pre><pre>    private $password;</pre><pre>    <em>/**<br>     * Create a new notification instance.<br>     *<br>     * @return void<br>     */<br>    </em>public function __construct($password)<br>    {<br>        $this-&gt;password = $password;<br>    }</pre><pre>    <em>/**<br>     * Get the notification&#39;s delivery channels.<br>     *<br>     * @param mixed $notifiable<br>     * @return array<br>     */<br>    </em>public function via($notifiable)<br>    {<br>        return [&#39;mail&#39;];<br>    }</pre><pre>    <em>/**<br>     * Get the mail representation of the notification.<br>     *<br>     * @param mixed $notifiable<br>     * @return \Illuminate\Notifications\Messages\MailMessage<br>     */<br>    </em>public function toMail($notifiable)<br>    {<br>        return (new MailMessage)<br>            -&gt;line(&#39;Your password is: &#39; . $this-&gt;password)<br>            -&gt;line(&#39;Note: This password is generated by the system!&#39;);<br>    }</pre><pre>    <em>/**<br>     * Get the array representation of the notification.<br>     *<br>     * @param mixed $notifiable<br>     * @return array<br>     */<br>    </em>public function toArray($notifiable)<br>    {<br>        return [<br>            <em>//<br>        </em>];<br>    }<br>}</pre><p>Make a controller <strong>UserController.php</strong></p><pre>// Command to make controller<br>php artisan make:controller UserController</pre><pre>// The controller will be generate in app/Http/Controllers/</pre><p>Write the below code in UserController.php</p><pre>&lt;?php<br><br>namespace App\Http\Controllers;<br><br>use App\Models\User;<br>use App\Notifications\PasswordToUserEmail;<br>use Illuminate\Http\Request;<br>use Illuminate\Support\Facades\Hash;<br>use Illuminate\Support\Str;<br><br>class UserController extends Controller<br>{<br>    function create()<br>    {<br>        return view(&#39;create-user&#39;);<br>    }<br><br>    function store(Request $request)<br>    {<br>        $request-&gt;validate(array(<br>            &#39;name&#39; =&gt; [&#39;required&#39;],<br>            &#39;email&#39; =&gt; [&#39;email&#39;, &#39;unique:users,email&#39;],<br>        ));<br><br>        $password = Str::<em>random</em>(16);<br><br>        $request[&#39;password&#39;] = Hash::make($password);<br>        $user = User::<em>create</em>($request-&gt;all());<br><br>        $user-&gt;notify(new PasswordToUserEmail($password));<br><br>        return redirect()-&gt;back();<br>    }<br>}</pre><p>Open the web.php file and add the following routes</p><pre>&lt;?php</pre><pre>use Illuminate\Support\Facades\Route;</pre><pre>Route::get(&#39;/&#39;, [\App\Http\Controllers\UserController::class, &#39;create&#39;])-&gt;name(&#39;create&#39;);<br>Route::post(&#39;/store&#39;, [\App\Http\Controllers\UserController::class, &#39;store&#39;])-&gt;name(&#39;store&#39;);</pre><p>Now create a simple form to create a new user and send a password via email. Create a blade file in resources/views/create-user.blade.php</p><pre>&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><br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css&quot;<br>          integrity=&quot;sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T&quot; crossorigin=&quot;anonymous&quot;&gt;<br><br>    &lt;title&gt;Send Random Password To New Users&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br><br>&lt;div class=&quot;w-50 container mt-5&quot;&gt;<br>    &lt;form action=&quot;{{ route(&#39;store&#39;) }}&quot; method=&quot;POST&quot;&gt;<br><br>        @csrf<br>        &lt;div class=&quot;form-group&quot;&gt;<br>            &lt;label for=&quot;userName&quot;&gt;Name&lt;/label&gt;<br>            &lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;form-control&quot; id=&quot;userName&quot; placeholder=&quot;Name...&quot;&gt;<br>            @error(&#39;name&#39;)<br>            &lt;strong class=&quot;text-danger&quot;&gt;{{ $message }}&lt;/strong&gt;<br>            @enderror<br>        &lt;/div&gt;<br>        &lt;div class=&quot;form-group&quot;&gt;<br>            &lt;label for=&quot;userEmail&quot;&gt;Email&lt;/label&gt;<br>            &lt;input type=&quot;email&quot; name=&quot;email&quot; class=&quot;form-control&quot; id=&quot;userEmail&quot; placeholder=&quot;Email...&quot;&gt;<br>            @error(&#39;email&#39;)<br>            &lt;strong class=&quot;text-danger&quot;&gt;{{ $message }}&lt;/strong&gt;<br>            @enderror<br>        &lt;/div&gt;<br>        &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>&lt;/div&gt;<br><br>&lt;script src=&quot;https://code.jquery.com/jquery-3.3.1.slim.min.js&quot;<br>        integrity=&quot;sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo&quot;<br>        crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;<br>&lt;script src=&quot;https://cdn.jsdelivr.net/npm/popper.js@1.14.7/dist/umd/popper.min.js&quot;<br>        integrity=&quot;sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1&quot;<br>        crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;<br>&lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/js/bootstrap.min.js&quot;<br>        integrity=&quot;sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM&quot;<br>        crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Everything is done :)</p><pre>// Run this command the run the laravel project<br>php artisan serve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*x12RZhvxR5FyToQ1wujLtA.png" /><figcaption>TESTING: Email with system-generated password :)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1593326ee519" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PayPal Payment Gateway Integration in Laravel 9]]></title>
            <link>https://itztalhaa.medium.com/paypal-payment-gateway-integration-in-laravel-b47cd7db953b?source=rss-be15e107652e------2</link>
            <guid isPermaLink="false">https://medium.com/p/b47cd7db953b</guid>
            <category><![CDATA[paypal-express-checkout]]></category>
            <category><![CDATA[paypal-gateway]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[paypal-in-laravel]]></category>
            <category><![CDATA[srmklive]]></category>
            <dc:creator><![CDATA[Talha Maqsood]]></dc:creator>
            <pubDate>Mon, 04 Jul 2022 10:14:29 GMT</pubDate>
            <atom:updated>2022-07-04T10:21:44.117Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*NSFGlcIw-KvxmPngAz8ABA.gif" /></figure><p>First of all, let&#39;s create a fresh laravel project</p><pre>composer create-project laravel/laravel paypal_laravel</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*kqJ0hYvP8vYqG8Q-gONwnw.png" /><figcaption>The project is successfully created :)</figcaption></figure><p>Now, go inside the project directory and open the folder in any code editor. I will recommend using <a href="https://www.jetbrains.com/phpstorm/download/">phpStorm</a></p><pre>cd paypal_laravel/</pre><p>Create a database in MySQL workbench (or PHPMyAdmin if you are using xampp or wamp). Open the .env file and configure the database credentials.</p><blockquote>Although, we have nothing to do with the database in this project bacause we are not querying any data from database. Just in case, you are querying you need to connect database.</blockquote><pre>DB_CONNECTION=mysql<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=&quot;your database name&quot;      // paypal_database<br>DB_USERNAME=&quot;your database username&quot;  // root<br>DB_PASSWORD=&quot;your database password&quot;  // password</pre><p>Now, for PayPal payment gateway integration I&#39;m going to use <a href="https://github.com/srmklive/laravel-paypal">srmklive/laravel-paypal</a> as this is the most powerful package laravel. So, run this command to install srmklive/laravel-paypal</p><pre>composer require srmklive/paypal</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*OdyKgVfXRjweyXgqGfdg1g.png" /><figcaption>srmklive/paypal successfully installed</figcaption></figure><p>After, the package is installed successfully. Now, go inside the config folder and open the app.php file and add the following lines,</p><pre>&#39;providers&#39; =&gt; [<br>    ...<br>    Srmklive\PayPal\Providers\PayPalServiceProvider::class,<br>    ...<br>],</pre><pre>&#39;aliases&#39; =&gt; [<br>    ...<br>    &#39;PayPal&#39; =&gt; Srmklive\PayPal\Facades\PayPal::class,<br>    ...<br>],</pre><p>Now, publish the package resources by running this below command,</p><pre>php artisan vendor:publish — provider=”Srmklive\PayPal\Providers\PayPalServiceProvider”</pre><p>This will create the paypal.php file in the config folder, so you can customize the paypal configurations as well. The paypal.php file is shown below,</p><pre>&lt;?php<br><em>/**<br> * PayPal Setting &amp; API Credentials<br> * Created by Raza Mehdi &lt;srmk@outlook.com&gt;.<br> */<br><br></em>return [<br>    &#39;mode&#39;    =&gt; env(&#39;PAYPAL_MODE&#39;, &#39;sandbox&#39;), <em>// Can only be &#39;sandbox&#39; Or &#39;live&#39;. If empty or invalid, &#39;live&#39; will be used.<br>    </em>&#39;sandbox&#39; =&gt; [<br>        &#39;client_id&#39;         =&gt; env(&#39;PAYPAL_SANDBOX_CLIENT_ID&#39;, &#39;&#39;),<br>        &#39;client_secret&#39;     =&gt; env(&#39;PAYPAL_SANDBOX_CLIENT_SECRET&#39;, &#39;&#39;),<br>        &#39;app_id&#39;            =&gt; &#39;APP-80W284485P519543T&#39;,<br>    ],<br>    &#39;live&#39; =&gt; [<br>        &#39;client_id&#39;         =&gt; env(&#39;PAYPAL_LIVE_CLIENT_ID&#39;, &#39;&#39;),<br>        &#39;client_secret&#39;     =&gt; env(&#39;PAYPAL_LIVE_CLIENT_SECRET&#39;, &#39;&#39;),<br>        &#39;app_id&#39;            =&gt; env(&#39;PAYPAL_LIVE_APP_ID&#39;, &#39;&#39;),<br>    ],<br><br>    &#39;payment_action&#39; =&gt; env(&#39;PAYPAL_PAYMENT_ACTION&#39;, &#39;Sale&#39;), <em>// Can only be &#39;Sale&#39;, &#39;Authorization&#39; or &#39;Order&#39;<br>    </em>&#39;currency&#39;       =&gt; env(&#39;PAYPAL_CURRENCY&#39;, &#39;USD&#39;),<br>    &#39;notify_url&#39;     =&gt; env(&#39;PAYPAL_NOTIFY_URL&#39;, &#39;&#39;), <em>// Change this accordingly for your application.<br>    </em>&#39;locale&#39;         =&gt; env(&#39;PAYPAL_LOCALE&#39;, &#39;en_US&#39;), <em>// force gateway language  i.e. it_IT, es_ES, en_US ... (for express checkout only)<br>    </em>&#39;validate_ssl&#39;   =&gt; env(&#39;PAYPAL_VALIDATE_SSL&#39;, true), <em>// Validate SSL when creating api client.<br></em>];</pre><p>Now, you need paypal client id and client secret. Follow this tutorial to get <a href="https://www.appinvoice.com/en/s/documentation/how-to-get-paypal-client-id-and-secret-key-22">client id and client secret</a></p><p>Add variables to .env once you get the client id and client secret. Currently, the mode is sandbox because of testing, you need to add sandbox client id and secret when the mode is a sandbox. BUT, for live mode, you need to add the real client id, client secret, and app id.</p><pre>PAYPAL_MODE=sandbox // or live</pre><pre>// for sandbox testing<br>PAYPAL_SANDBOX_CLIENT_ID=xyz...<br>PAYPAL_SANDBOX_CLIENT_SECRET=xyz...</pre><pre>// for live<br>PAYPAL_LIVE_CLIENT_ID=xyz...<br>PAYPAL_LIVE_CLIENT_SECRET=xyz...<br>PAYPAL_LIVE_APP_ID=12xyz...</pre><p>Lets create a controller for paypal transactions logic</p><pre>php artisan make:controller PaypalController</pre><p>Write the code in PaypalController.php</p><pre>&lt;?php<br><br>namespace App\Http\Controllers;<br><br>use Illuminate\Http\Request;<br>use Illuminate\Support\Facades\DB;<br>use Illuminate\Support\Facades\Session;<br>use Srmklive\PayPal\Services\PayPal as PayPalClient;<br><br>class PaypalController extends Controller<br>{<br>    <em>/**<br>     * process transaction.<br>     *<br>     * @return \Illuminate\Http\RedirectResponse<br>     */<br>    </em>public function processTransaction($amount)<br>    {<br>        try {<br>            $provider = new <em>PayPalClient</em>;<br>            $provider-&gt;setApiCredentials(config(&#39;paypal&#39;));<br>            $paypalToken = $provider-&gt;getAccessToken();<br><br>            $response = $provider-&gt;createOrder([<br>                &quot;intent&quot; =&gt; &quot;CAPTURE&quot;,<br>                &quot;application_context&quot; =&gt; [<br>                    &quot;return_url&quot; =&gt; route(&#39;successTransaction&#39;),<br>                    &quot;cancel_url&quot; =&gt; route(&#39;cancelTransaction&#39;),<br>                ],<br>                &quot;purchase_units&quot; =&gt; [<br>                    0 =&gt; [<br>                        &quot;amount&quot; =&gt; [<br>                            &quot;currency_code&quot; =&gt; &quot;USD&quot;,<br>                            &quot;value&quot; =&gt; (int)$amount<br>                        ]<br>                    ]<br>                ]<br>            ]);<br><br>            if (isset($response[&#39;id&#39;]) &amp;&amp; $response[&#39;id&#39;] != null) {<br>                foreach ($response[&#39;links&#39;] as $link) {<br>                    if ($link[&#39;rel&#39;] == &#39;approve&#39;) {<br>                        return redirect()-&gt;away($link[&#39;href&#39;]);<br>                    }<br>                }<br><br>                Session::flash(&#39;error&#39;, &#39;Something went wrong.&#39;);<br>                return redirect()-&gt;route(&#39;homepage&#39;);<br><br>            } else {<br>                Session::flash(&#39;error&#39;, $response[&#39;message&#39;] ?? &#39;Something went wrong.&#39;);<br>                return redirect()-&gt;route(&#39;homepage&#39;);<br>            }<br>        } catch (\Throwable $throwable) {<br>            Session::flash(&#39;error&#39;, $throwable-&gt;getMessage() ?? &#39;Something went wrong.&#39;);<br>            return redirect()-&gt;route(&#39;homepage&#39;);<br>        }<br>    }<br><br>    <em>/**<br>     * success transaction.<br>     *<br>     * @return \Illuminate\Http\RedirectResponse<br>     */<br>    </em>public function successTransaction(Request $request)<br>    {<br>        DB::beginTransaction();<br>        try {<br>            $provider = new <em>PayPalClient</em>;<br>            $provider-&gt;setApiCredentials(config(&#39;paypal&#39;));<br>            $provider-&gt;getAccessToken();<br>            $response = $provider-&gt;capturePaymentOrder($request[&#39;token&#39;]);<br><br>            if (isset($response[&#39;status&#39;]) &amp;&amp; $response[&#39;status&#39;] == &#39;COMPLETED&#39;) {<br>                Session::flash(&#39;success&#39;, &#39;Transaction Successfully Completed.&#39;);<br>                return redirect()-&gt;route(&#39;homepage&#39;);<br>            } else {<br>                DB::rollBack();<br>                Session::flash(&#39;error&#39;, $response[&#39;message&#39;] ?? &#39;Something went wrong.&#39;);<br>                return redirect()-&gt;route(&#39;homepage&#39;);<br>            }<br>        } catch (\Throwable $throwable) {<br>            DB::rollBack();<br>            Session::flash(&#39;error&#39;, $throwable-&gt;getMessage() ?? &#39;Something went wrong.&#39;);<br>            return redirect()-&gt;route(&#39;homepage&#39;);<br>        }<br>    }<br><br>    <em>/**<br>     * cancel transaction.<br>     *<br>     * @return \Illuminate\Http\RedirectResponse<br>     */<br>    </em>public function cancelTransaction(Request $request)<br>    {<br>        Session::flash(&#39;error&#39;, &#39;Payment cancelled.&#39;);<br>        return redirect()-&gt;route(&#39;homepage&#39;);<br>    }<br>}</pre><p>Open the web.php file inside the routes/web.php and write the following routes</p><pre>Route::get(&#39;/&#39;, function () {<br>    return view(&#39;index&#39;);<br>})-&gt;name(&#39;homepage&#39;);<br><br>Route::get(&#39;process-transaction/{amount}&#39;, [\App\Http\Controllers\PaypalController::class, &#39;processTransaction&#39;])-&gt;name(&#39;processTransaction&#39;);<br>Route::get(&#39;success-transaction&#39;, [\App\Http\Controllers\PaypalController::class, &#39;successTransaction&#39;])-&gt;name(&#39;successTransaction&#39;);<br>Route::get(&#39;cancel-transaction&#39;, [\App\Http\Controllers\PaypalController::class, &#39;cancelTransaction&#39;])-&gt;name(&#39;cancelTransaction&#39;);</pre><p>Create the index.blade.php file inside the resources/views folder</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;eng&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&quot;&gt;<br>    &lt;title&gt;Paypal Payment Gateway&lt;/title&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;div class=&quot;container py-2 text-center&quot;&gt;<br><br>    @if(Session::<em>has</em>(&#39;success&#39;))<br>        &lt;div class=&quot;alert alert-success&quot;&gt;{{ Session::get(&#39;success&#39;) }}&lt;/div&gt;<br>    @endif<br>    @if(Session::<em>has</em>(&#39;error&#39;))<br>        &lt;div class=&quot;alert alert-danger&quot;&gt;{{ Session::get(&#39;error&#39;) }}&lt;/div&gt;<br>    @endif<br><br>    &lt;a class=&quot;btn btn-info&quot; href=&quot;{{ route(&#39;processTransaction&#39;, [&#39;amount&#39; =&gt; 100]) }}&quot;&gt;Pay 100$ with PayPal&lt;/a&gt;<br>&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Alright, everything is done now just run the server and test the project.</p><pre>php artisan serve</pre><p>Run the project on browser: <a href="http://127.0.0.1:8000/"><strong><em>http://127.0.0.1:8000/</em></strong></a></p><p>If you have any questions feel free to contact me :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b47cd7db953b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Admin Panel and CRUD Generator in Laravel 8 using Craftable]]></title>
            <link>https://itztalhaa.medium.com/admin-panel-and-crud-generator-in-laravel-8-using-craftable-f9946d1627d1?source=rss-be15e107652e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9946d1627d1</guid>
            <category><![CDATA[crud-laravel]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[craftable]]></category>
            <category><![CDATA[admin-panel]]></category>
            <dc:creator><![CDATA[Talha Maqsood]]></dc:creator>
            <pubDate>Fri, 21 May 2021 12:36:33 GMT</pubDate>
            <atom:updated>2021-05-21T12:36:33.816Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pmpegd7km4SR1yFPNy0Klg.png" /><figcaption>Craftable</figcaption></figure><p>First create a new laravel project,</p><pre>composer create-project --prefer-dist laravel/laravel:^8.0 craftable</pre><pre># go inside the project folder<br>cd craftable</pre><p>Now, add the craftable to your laravel project,</p><pre>composer require brackets/craftable<br>composer require --dev brackets/admin-generator</pre><p>Add your database credientials to .env file,</p><pre>DB_CONNECTION=mysql<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=craftable<br>DB_USERNAME=root<br>DB_PASSWORD=password</pre><p>Install the craftable,</p><pre>php artisan craftable:install</pre><p>After successfully running this command your password will be automatically generate, save that password to clipboard. (In the below picture the highlighted is password)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*ZjMI_DS_zi_Sm4qCA52MMw.png" /><figcaption>Craftable Laravel</figcaption></figure><p>Now, install the node modules,</p><pre>npm install<br>npm run dev</pre><p>Craftable is successfully install and now you can run the project on browser.</p><pre>php artisan serve</pre><p><a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a></p><p>You can login by using:</p><p><strong>Email</strong>: administrator@brackets.sk</p><p><strong>Password</strong>: you copied a while before</p><p>Now, let’s create a crud. you just need to create a migration and leave it to the craftable to make a crud for you.</p><p>e.g. create a migration for product</p><pre>php artisan make:migration create_products_table</pre><pre># migration path<br># database/migrations/2021_05_21_115426_create_products_table.php</pre><p>Add some columns to the migration,</p><pre>&lt;?php<br><br>use Illuminate\Database\Migrations\Migration;<br>use Illuminate\Database\Schema\Blueprint;<br>use Illuminate\Support\Facades\Schema;<br><br>class CreateProductsTable extends Migration<br>{<br>    <em>/**<br>     * Run the migrations.<br>     *<br>     * @return void<br>     */<br>    </em>public function up()<br>    {<br>        Schema::create(&#39;products&#39;, function (Blueprint $table) {<br>            $table-&gt;id();<br>            $table-&gt;string(&#39;name&#39;);<br>            $table-&gt;string(&#39;slug&#39;)-&gt;nullable();<br>            $table-&gt;boolean(&#39;status&#39;)-&gt;default(true);<br>            $table-&gt;timestamps();<br>        });<br>    }<br><br>    <em>/**<br>     * Reverse the migrations.<br>     *<br>     * @return void<br>     */<br>    </em>public function down()<br>    {<br>        Schema::dropIfExists(&#39;products&#39;);<br>    }<br>}</pre><p>Now, just hit the following command to make the whole crud,</p><pre>php artisan admin:generate products</pre><p>Now, compile the the laravel mix</p><pre>npm run dev</pre><p>Crud is generated, now you can run the project,</p><pre>php artisan serve</pre><p><a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9946d1627d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Config Mailtrap in Laravel 8]]></title>
            <link>https://itztalhaa.medium.com/config-mailtrap-in-laravel-8-8be3b4abbcb?source=rss-be15e107652e------2</link>
            <guid isPermaLink="false">https://medium.com/p/8be3b4abbcb</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[mailtrap]]></category>
            <category><![CDATA[mailbox]]></category>
            <category><![CDATA[laravel8]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Talha Maqsood]]></dc:creator>
            <pubDate>Tue, 18 May 2021 13:06:33 GMT</pubDate>
            <atom:updated>2021-05-18T13:15:01.792Z</atom:updated>
            <content:encoded><![CDATA[<p>Go to the website and signup by using your email</p><p><a href="https://mailtrap.io/register/signup">Mailtrap - Safe Email Testing</a></p><p>Select the signup method you can signup using google account, github etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0HjaVNL7DtGn-pozPVYXLw.png" /><figcaption>Mailtrap Signup</figcaption></figure><p>I’ll signup by email So, after filling the signup form and checking the recaptcha, click on the confirmation mail that is sent on your email by mailtrap.</p><p>So, after confirming the account you will be land on your mailtrap dashboard.</p><p>Then, go into the <strong>My Inbox</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3_e_uT49APOhNocosnM2Sw.png" /><figcaption>Mailtrap Dashboard</figcaption></figure><p>Now, select the technology for which you use the mailtrap, we are using laravel so, select the laravel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pLgT1isCCrIU1odSp7UJIA.png" /></figure><p>Copy this 6 lines of code and replace these lines in the .env file as it is like:</p><pre>MAIL_MAILER=smtp<br>MAIL_HOST=smtp.mailtrap.io<br>MAIL_PORT=2525<br>MAIL_USERNAME=25b738a6fc7347<br>MAIL_PASSWORD=c744a4d39bbc8b<br>MAIL_ENCRYPTION=tls</pre><pre>MAIL_FROM_ADDRESS=admin@codetechsol.com<br>MAIL_FROM_NAME=&quot;${APP_NAME}&quot;</pre><p>Save the .env file and clear the configurations. The mailtrap is configured successfully. Now you can receive mail to the mailtrap inbox.</p><pre>php artisan optimize:clear</pre><blockquote><em>I hope it helps!</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8be3b4abbcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple product crud in laravel-8 with simple pagination]]></title>
            <link>https://itztalhaa.medium.com/simple-product-crud-in-laravel-8-with-simple-pagination-72ef3500c2fa?source=rss-be15e107652e------2</link>
            <guid isPermaLink="false">https://medium.com/p/72ef3500c2fa</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[pagination-in-laravel]]></category>
            <category><![CDATA[laravel8]]></category>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Talha Maqsood]]></dc:creator>
            <pubDate>Mon, 17 May 2021 17:30:10 GMT</pubDate>
            <atom:updated>2021-05-17T17:39:55.490Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*3KQ7tiue0rxjTd8dNypolA.png" /><figcaption>Laravel-8 simple product crud with simple pagination</figcaption></figure><p><strong>NOTE</strong>: Before start make sure php, composer, nodejs, npm and mysql must be installed on your system.</p><p>To create a new laravel project by using composer, open the terminal where you want to create project:</p><pre>composer create-project --prefer-dist laravel/laravel:^8.0 crud</pre><p>After the installation complete then , go into the project folder;</p><pre>cd crud</pre><p>Let’s make a product crud in laravel 8, so first thing first we have to make a migration for product:</p><pre>php artisan make:migration create_products_table</pre><p><strong>Note:</strong></p><p>1- The syntax to create migration, you must type the ‘<strong>create</strong>’ at the first and ‘table’ at the last and in the middle ‘<strong>table name</strong>’ with the ‘_’ concatenation.</p><p>2- The table name must be plural.</p><p>Now make columns in the table (products) we have just created.</p><p>database/migrations/2021_05_17_131915_create_products_table.php</p><pre>&lt;?php<br><br>use Illuminate\Database\Migrations\Migration;<br>use Illuminate\Database\Schema\Blueprint;<br>use Illuminate\Support\Facades\Schema;<br><br>class CreateProductsTable extends Migration<br>{<br>    <em>/**<br>     * Run the migrations.<br>     *<br>     * @return void<br>     */<br>    </em>public function up()<br>    {<br>        Schema::create(&#39;products&#39;, function (Blueprint $table) {<br>            $table-&gt;id();<br>            $table-&gt;string(&#39;name&#39;)-&gt;nullable();<br>            $table-&gt;longText(&#39;description&#39;)-&gt;nullable();<br>            $table-&gt;string(&#39;color&#39;)-&gt;nullable();<br>            $table-&gt;bigInteger(&#39;price&#39;)-&gt;nullable();<br>            $table-&gt;bigInteger(&#39;weight&#39;)-&gt;nullable();<br>            $table-&gt;timestamps();<br>        });<br>    }<br><br>    <em>/**<br>     * Reverse the migrations.<br>     *<br>     * @return void<br>     */<br>    </em>public function down()<br>    {<br>        Schema::dropIfExists(&#39;products&#39;);<br>    }<br>}</pre><p>Now, create a model of products, model is used to handle the business logic&#39;s, So,</p><pre>php artisan make:model Product</pre><p>The product model look like this:</p><pre>&lt;?php<br><br>namespace App\Models;<br><br>use Illuminate\Database\Eloquent\Factories\HasFactory;<br>use Illuminate\Database\Eloquent\Model;<br><br>class Product extends Model<br>{<br>    use HasFactory;<br><br>    <em>/**<br>     * The attributes that are mass assignable.<br>     *<br>     * @var array<br>     */<br>    </em>protected $fillable = [<br>      &#39;name&#39;,<br>      &#39;description&#39;,<br>      &#39;color&#39;,<br>      &#39;price&#39;,<br>      &#39;weight&#39;,<br>    ];<br>}</pre><p>Now, create a controller to process HTTP requests and return back the result to the web browser and also to communicate with the models and views.</p><pre>php artisan make:controller ProductController -r</pre><pre># -r means resource, used to make the resource controller </pre><p>Let’s write the code for product crud in this controller,</p><p>app/Http/Controllers/ProductController.php</p><pre>&lt;?php<br><br>namespace App\Http\Controllers;<br><br>use App\Models\Product;<br>use Illuminate\Http\Request;<br><br>class ProductController extends Controller<br>{<br>    <em>/**<br>     * Display a listing of the resource.<br>     *<br>     * @return \Illuminate\Http\Response<br>     */<br>    </em>public function index()<br>    {<br>        $products = Product::<em>simplePaginate</em>(2);<br><br>        return view(&#39;index&#39;, <em>compact</em>(&#39;products&#39;, $products));<br>    }<br><br>    <em>/**<br>     * Show the form for creating a new resource.<br>     *<br>     * @return \Illuminate\Http\Response<br>     */<br>    </em>public function create()<br>    {<br>        return view(&#39;create&#39;);<br>    }<br><br>    <em>/**<br>     * Store a newly created resource in storage.<br>     *<br>     * @param  \Illuminate\Http\Request  $request<br>     * @return \Illuminate\Http\Response<br>     */<br>    </em>public function store(Request $request)<br>    {<br>        $product = Product::<em>create</em>([<br>            &#39;name&#39; =&gt; $request-&gt;name,<br>            &#39;color&#39; =&gt; $request-&gt;color,<br>            &#39;weight&#39; =&gt; $request-&gt;weight,<br>            &#39;price&#39; =&gt; $request-&gt;price,<br>            &#39;description&#39; =&gt; $request-&gt;description,<br>        ]);<br><br>        return redirect()-&gt;back()-&gt;with(&#39;success&#39;, &#39;Product successfully stored.&#39;);<br>    }<br><br>    <em>/**<br>     * Display the specified resource.<br>     *<br>     * @param  int  $id<br>     * @return \Illuminate\Http\Response<br>     */<br>    </em>public function show($id)<br>    {<br>        $product = Product::<em>findOrFail</em>($id);<br><br>        return view(&#39;show&#39;, <em>compact</em>(&#39;product&#39;, $product));<br>    }<br><br>    <em>/**<br>     * Show the form for editing the specified resource.<br>     *<br>     * @param  int  $id<br>     * @return \Illuminate\Http\Response<br>     */<br>    </em>public function edit($id)<br>    {<br>        $product = Product::<em>findOrFail</em>($id);<br><br>        return view(&#39;edit&#39;, <em>compact</em>(&#39;product&#39;, $product));<br>    }<br><br>    <em>/**<br>     * Update the specified resource in storage.<br>     *<br>     * @param  \Illuminate\Http\Request  $request<br>     * @param  int  $id<br>     * @return \Illuminate\Http\Response<br>     */<br>    </em>public function update(Request $request, $id)<br>    {<br>        $product = Product::<em>findOrFail</em>($id);<br><br>        $product-&gt;update([<br>            &#39;name&#39; =&gt; $request-&gt;name,<br>            &#39;color&#39; =&gt; $request-&gt;color,<br>            &#39;weight&#39; =&gt; $request-&gt;weight,<br>            &#39;price&#39; =&gt; $request-&gt;price,<br>            &#39;description&#39; =&gt; $request-&gt;description,<br>        ]);<br><br>        return redirect()-&gt;back()-&gt;with(&#39;success&#39;, &#39;Product successfully updated.&#39;);<br>    }<br><br>    <em>/**<br>     * Remove the specified resource from storage.<br>     *<br>     * @param  int  $id<br>     * @return \Illuminate\Http\Response<br>     */<br>    </em>public function destroy($id)<br>    {<br>        $product = Product::<em>findOrFail</em>($id);<br><br>        $product-&gt;delete();<br><br>        return redirect()-&gt;back()-&gt;with(&#39;success&#39;, &#39;Product successfully deleted.&#39;);<br>    }<br>}</pre><p>Now, create the following blade file as mention below:</p><p>resources/views/layouts/master.blade.php</p><pre>&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;<br>          content=&quot;width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0&quot;&gt;<br>    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&gt;<br>    &lt;title&gt;Product Crud&lt;/title&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br><br>    &lt;div class=&quot;row justify-content-center mt-5&quot;&gt;<br>        &lt;div class=&quot;col-6&quot;&gt;<br>            @yield(&#39;content&#39;)<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br><br>    &lt;script src=&quot;https://code.jquery.com/jquery-3.6.0.min.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>resources/views/create.blade.php</p><pre>@extends(&#39;layouts.master&#39;)<br><br>@section(&#39;content&#39;)<br><br>    &lt;div class=&quot;d-flex justify-content-between mb-4&quot;&gt;<br>        &lt;h3&gt;Create Product&lt;/h3&gt;<br>        &lt;a class=&quot;btn btn-success btn-sm&quot; href=&quot;{{ route(&#39;index&#39;) }}&quot;&gt;List Products&lt;/a&gt;<br>    &lt;/div&gt;<br><br>    @if(session()-&gt;has(&#39;success&#39;))<br>        &lt;label class=&quot;alert alert-success w-100&quot;&gt;{{session(&#39;success&#39;)}}&lt;/label&gt;<br>    @elseif(session()-&gt;has(&#39;error&#39;))<br>        &lt;label class=&quot;alert alert-danger w-100&quot;&gt;{{session(&#39;error&#39;)}}&lt;/label&gt;<br>    @endif<br><br>    &lt;form action=&quot;{{ route(&#39;store&#39;) }}&quot; method=&quot;POST&quot;&gt;<br><br>        @csrf<br>        &lt;div class=&quot;form-group&quot;&gt;<br>            &lt;label&gt;Name&lt;/label&gt;<br>            &lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;form-control&quot; placeholder=&quot;product name&quot;&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;form-group&quot;&gt;<br>            &lt;label&gt;Color&lt;/label&gt;<br>            &lt;input type=&quot;color&quot; name=&quot;color&quot; class=&quot;form-control&quot; placeholder=&quot;product color&quot;&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;row&quot;&gt;<br>            &lt;div class=&quot;col-12&quot;&gt;<br>                &lt;div class=&quot;row&quot;&gt;<br>                    &lt;div class=&quot;col-md-6&quot;&gt;<br>                        &lt;div class=&quot;form-group&quot;&gt;<br>                            &lt;label&gt;Weight&lt;/label&gt;<br>                            &lt;input type=&quot;text&quot; name=&quot;weight&quot; class=&quot;form-control&quot; placeholder=&quot;product weight&quot;&gt;<br>                        &lt;/div&gt;<br>                    &lt;/div&gt;<br>                    &lt;div class=&quot;col-md-6&quot;&gt;<br>                        &lt;div class=&quot;form-group&quot;&gt;<br>                            &lt;label&gt;Price&lt;/label&gt;<br>                            &lt;input type=&quot;text&quot; name=&quot;price&quot; class=&quot;form-control&quot; placeholder=&quot;product price&quot;&gt;<br>                        &lt;/div&gt;<br>                    &lt;/div&gt;<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;form-group&quot;&gt;<br>            &lt;label&gt;Description&lt;/label&gt;<br>            &lt;textarea name=&quot;description&quot; rows=&quot;5&quot; placeholder=&quot;product description&quot; class=&quot;form-control&quot;&gt;&lt;/textarea&gt;<br>        &lt;/div&gt;<br>        &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>@endsection</pre><p>resources/views/edit.blade.php</p><pre>@extends(&#39;layouts.master&#39;)<br><br>@section(&#39;content&#39;)<br><br>    &lt;div class=&quot;d-flex justify-content-between mb-4&quot;&gt;<br>        &lt;h3&gt;Edit Product&lt;/h3&gt;<br>        &lt;a class=&quot;btn btn-success btn-sm&quot; href=&quot;{{ route(&#39;index&#39;) }}&quot;&gt;List Products&lt;/a&gt;<br>    &lt;/div&gt;<br><br>    @if(session()-&gt;has(&#39;success&#39;))<br>        &lt;label class=&quot;alert alert-success w-100&quot;&gt;{{session(&#39;success&#39;)}}&lt;/label&gt;<br>    @elseif(session()-&gt;has(&#39;error&#39;))<br>        &lt;label class=&quot;alert alert-danger w-100&quot;&gt;{{session(&#39;error&#39;)}}&lt;/label&gt;<br>    @endif<br><br>    &lt;form action=&quot;{{ route(&#39;update&#39;, [&#39;id&#39; =&gt; $product-&gt;id]) }}&quot; method=&quot;POST&quot;&gt;<br><br>        @csrf<br>        &lt;div class=&quot;form-group&quot;&gt;<br>            &lt;label&gt;Name&lt;/label&gt;<br>            &lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;form-control&quot; placeholder=&quot;product name&quot; value=&quot;{{ $product-&gt;name }}&quot;&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;form-group&quot;&gt;<br>            &lt;label&gt;Color&lt;/label&gt;<br>            &lt;input type=&quot;color&quot; name=&quot;color&quot; class=&quot;form-control&quot; placeholder=&quot;product color&quot; value=&quot;{{ $product-&gt;color }}&quot;&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;row&quot;&gt;<br>            &lt;div class=&quot;col-12&quot;&gt;<br>                &lt;div class=&quot;row&quot;&gt;<br>                    &lt;div class=&quot;col-md-6&quot;&gt;<br>                        &lt;div class=&quot;form-group&quot;&gt;<br>                            &lt;label&gt;Weight&lt;/label&gt;<br>                            &lt;input type=&quot;text&quot; name=&quot;weight&quot; class=&quot;form-control&quot; placeholder=&quot;product weight&quot; value=&quot;{{ $product-&gt;weight }}&quot;&gt;<br>                        &lt;/div&gt;<br>                    &lt;/div&gt;<br>                    &lt;div class=&quot;col-md-6&quot;&gt;<br>                        &lt;div class=&quot;form-group&quot;&gt;<br>                            &lt;label&gt;Price&lt;/label&gt;<br>                            &lt;input type=&quot;text&quot; name=&quot;price&quot; class=&quot;form-control&quot; placeholder=&quot;product price&quot; value=&quot;{{ $product-&gt;price }}&quot;&gt;<br>                        &lt;/div&gt;<br>                    &lt;/div&gt;<br>                &lt;/div&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;form-group&quot;&gt;<br>            &lt;label&gt;Description&lt;/label&gt;<br>            &lt;textarea name=&quot;description&quot; rows=&quot;5&quot; placeholder=&quot;product description&quot; class=&quot;form-control&quot;&gt;{{ $product-&gt;description }}&lt;/textarea&gt;<br>        &lt;/div&gt;<br>        &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>@endsection</pre><p>resources/views/index.blade.php</p><pre>@extends(&#39;layouts.master&#39;)<br><br>@section(&#39;content&#39;)<br><br>    &lt;div class=&quot;d-flex justify-content-between mb-4&quot;&gt;<br>        &lt;h3&gt;Products List&lt;/h3&gt;<br>        &lt;a class=&quot;btn btn-success btn-sm&quot; href=&quot;{{ route(&#39;create&#39;) }}&quot;&gt;Create New&lt;/a&gt;<br>    &lt;/div&gt;<br><br>    @if(session()-&gt;has(&#39;success&#39;))<br>        &lt;label class=&quot;alert alert-success w-100&quot;&gt;{{session(&#39;success&#39;)}}&lt;/label&gt;<br>    @elseif(session()-&gt;has(&#39;error&#39;))<br>        &lt;label class=&quot;alert alert-danger w-100&quot;&gt;{{session(&#39;error&#39;)}}&lt;/label&gt;<br>    @endif<br><br>    &lt;table class=&quot;table table-striped&quot;&gt;<br>        &lt;thead&gt;<br>        &lt;tr&gt;<br>            &lt;th&gt;Created At&lt;/th&gt;<br>            &lt;th&gt;Name&lt;/th&gt;<br>            &lt;th&gt;Weight&lt;/th&gt;<br>            &lt;th&gt;Price&lt;/th&gt;<br>            &lt;th&gt;Action&lt;/th&gt;<br>        &lt;/tr&gt;<br>        &lt;/thead&gt;<br>        &lt;tbody&gt;<br><br>        @foreach($products as $product)<br>            &lt;tr&gt;<br>                &lt;td&gt;{{ $product-&gt;created_at }}&lt;/td&gt;<br>                &lt;td&gt;{{ $product-&gt;name }}&lt;/td&gt;<br>                &lt;td&gt;{{ $product-&gt;weight }}&lt;/td&gt;<br>                &lt;td&gt;{{ $product-&gt;price }}&lt;/td&gt;<br>                &lt;td&gt;<br>                    &lt;a href=&quot;{{ route(&#39;edit&#39;, [&#39;id&#39; =&gt; $product-&gt;id]) }}&quot; class=&quot;btn btn-success btn-sm&quot;&gt;Edit&lt;/a&gt;<br>                    &lt;a href=&quot;{{ route(&#39;show&#39;, [&#39;id&#39; =&gt; $product-&gt;id]) }}&quot; class=&quot;btn btn-info btn-sm&quot;&gt;Show&lt;/a&gt;<br>                    &lt;form action=&quot;{{ route(&#39;delete&#39;, [&#39;id&#39; =&gt; $product-&gt;id]) }}&quot; method=&quot;POST&quot; class=&quot;d-inline-block&quot;&gt;<br>                        @csrf<br>                        &lt;button type=&quot;submit&quot; class=&quot;btn btn-danger btn-sm&quot;&gt;Delete&lt;/button&gt;<br>                    &lt;/form&gt;<br>                &lt;/td&gt;<br>            &lt;/tr&gt;<br>        @endforeach<br><br>        &lt;/tbody&gt;<br>    &lt;/table&gt;<br><br>    &lt;div class=&quot;d-flex justify-content-between&quot;&gt;<br>        {{ $products-&gt;render() }}<br>    &lt;/div&gt;<br><br>@endsection</pre><p>resources/views/show.blade.php</p><pre>@extends(&#39;layouts.master&#39;)<br><br>@section(&#39;content&#39;)<br><br>    &lt;div class=&quot;d-flex justify-content-between mb-4&quot;&gt;<br>        &lt;h3&gt;Show Product&lt;/h3&gt;<br>        &lt;a class=&quot;btn btn-success btn-sm&quot; href=&quot;{{ route(&#39;index&#39;) }}&quot;&gt;List Products&lt;/a&gt;<br>    &lt;/div&gt;<br><br>    &lt;div class=&quot;form-group&quot;&gt;<br>        &lt;label&gt;Name&lt;/label&gt;<br>        &lt;input type=&quot;text&quot; name=&quot;name&quot; class=&quot;form-control&quot; value=&quot;{{ $product-&gt;name }}&quot; disabled&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;form-group&quot;&gt;<br>        &lt;label&gt;Color&lt;/label&gt;<br>        &lt;input type=&quot;color&quot; name=&quot;color&quot; class=&quot;form-control&quot; value=&quot;{{ $product-&gt;color }}&quot; disabled&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;form-group&quot;&gt;<br>        &lt;label&gt;Weight&lt;/label&gt;<br>        &lt;input type=&quot;text&quot; name=&quot;weight&quot; class=&quot;form-control&quot; value=&quot;{{ $product-&gt;weight }}&quot; disabled&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;form-group&quot;&gt;<br>        &lt;label&gt;Description&lt;/label&gt;<br>        &lt;textarea name=&quot;description&quot; rows=&quot;5&quot; placeholder=&quot;product description&quot; class=&quot;form-control&quot; disabled&gt;{{ $product-&gt;description }}&lt;/textarea&gt;<br>    &lt;/div&gt;<br>@endsection</pre><p>Now, write the routes in the web.php file:</p><p>routes/web.php</p><pre>&lt;?php<br><br>use Illuminate\Support\Facades\Route;<br><br><em>/*<br>|--------------------------------------------------------------------------<br>| Web Routes<br>|--------------------------------------------------------------------------<br>|<br>| Here is where you can register web routes for your application. These<br>| routes are loaded by the RouteServiceProvider within a group which<br>| contains the &quot;web&quot; middleware group. Now create something great!<br>|<br>*/<br><br>//Route::get(&#39;/&#39;, function () {<br>//    return view(&#39;welcome&#39;);<br>//});<br><br></em>Route::get(&#39;/&#39;, [\App\Http\Controllers\ProductController::class, &#39;index&#39;])-&gt;name(&#39;index&#39;);<br>Route::get(&#39;/create&#39;, [\App\Http\Controllers\ProductController::class, &#39;create&#39;])-&gt;name(&#39;create&#39;);<br>Route::get(&#39;/show/{id}&#39;, [\App\Http\Controllers\ProductController::class, &#39;show&#39;])-&gt;name(&#39;show&#39;);<br>Route::get(&#39;/edit/{id}&#39;, [\App\Http\Controllers\ProductController::class, &#39;edit&#39;])-&gt;name(&#39;edit&#39;);<br>Route::post(&#39;/update/{id}&#39;, [\App\Http\Controllers\ProductController::class, &#39;update&#39;])-&gt;name(&#39;update&#39;);<br>Route::post(&#39;/store&#39;, [\App\Http\Controllers\ProductController::class, &#39;store&#39;])-&gt;name(&#39;store&#39;);<br>Route::post(&#39;/delete/{id}&#39;, [\App\Http\Controllers\ProductController::class, &#39;destroy&#39;])-&gt;name(&#39;delete&#39;);</pre><p>Add the database credentials in the .env file:</p><pre>DB_CONNECTION=mysql<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=laravel # your database name<br>DB_USERNAME=root #your database username<br>DB_PASSWORD=password #your database password</pre><p>The final step is to run the migration:</p><pre>php artisan migrate</pre><p>Now, run the project and test:</p><pre>php artisan serve</pre><p><a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a></p><blockquote>I hope it helps!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72ef3500c2fa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel-8 Authentication with Breeze]]></title>
            <link>https://itztalhaa.medium.com/laravel-8-authentication-with-breeze-4e251955ce44?source=rss-be15e107652e------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e251955ce44</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel8]]></category>
            <category><![CDATA[laravel-authentication]]></category>
            <category><![CDATA[breeze]]></category>
            <dc:creator><![CDATA[Talha Maqsood]]></dc:creator>
            <pubDate>Sat, 15 May 2021 10:13:17 GMT</pubDate>
            <atom:updated>2021-05-15T10:26:07.616Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*hOW4blnfGi5p-NrNoRqXng.png" /><figcaption>Laravel Breeze Auth Scaffolding</figcaption></figure><p>Requirements:</p><p>Php</p><p>Composer</p><p>Node &amp; Npm</p><p>MySql</p><p>First of all create a new laravel project, just hit the below command:</p><pre>composer create-project --prefer-dist laravel/laravel:^8.0 FirstProject</pre><pre># if your composer install globally then you may hit this command<br>laravel new FirstProject</pre><p>After the installation completes, then go into the project folder.</p><pre>cd FirstProject</pre><p>OPTIONAL: If you are creating new laravel project this will automatically create the .env file then you don’t need this step but if your don’t have the .env file you must perform this step.</p><p>Copy the .env.example file to .env and generate the application key:</p><pre>cp .env.example .env<br>php artisan key:generate<br>php artisan optimize:clear</pre><p>Now we have to add and install the breeze to our project, by using these commands:</p><pre>composer require laravel/breeze --dev</pre><p>Installation of breeze by typing below command:</p><pre>php artisan breeze:install</pre><p>Now, install the node modules:</p><pre>npm install<br>npm run dev</pre><p>Create a database and set the credentials in the .env file, just like</p><pre>DB_CONNECTION=mysql<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=breeze # your database name<br>DB_USERNAME=admin #your database username<br>DB_PASSWORD=password #your database password</pre><p>Now, clear the config but, remember if you are using laravel 8 then you may don&#39;t need to run this command but if you wanna hit this command it’s up to you. Nothing will change it just clear the configuration.</p><pre>php artisan optimize:clear</pre><p>The final step is to run the migrations:</p><pre>php artisan migrate</pre><p>Breeze Authentication is done, check the project is running properly:</p><pre>php artisan serve</pre><p><a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a></p><blockquote><em>I hope it helps!</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e251955ce44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Send Mail Using Gmail SMTP Server in Laravel 8.9.0]]></title>
            <link>https://itztalhaa.medium.com/send-mail-using-gmail-smtp-server-in-laravel-8-9-0-cd317ae6a45a?source=rss-be15e107652e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd317ae6a45a</guid>
            <category><![CDATA[smtp]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[gmail-smtp-server]]></category>
            <category><![CDATA[gmail-smtp-settings]]></category>
            <category><![CDATA[gmail-smtp]]></category>
            <dc:creator><![CDATA[Talha Maqsood]]></dc:creator>
            <pubDate>Sat, 10 Oct 2020 18:39:21 GMT</pubDate>
            <atom:updated>2024-05-22T10:31:54.930Z</atom:updated>
            <content:encoded><![CDATA[<h3>Generate Gmail SMTP Credentials(with images)</h3><p>6 very easy steps to send mail using Gmail SMTP in laravel 8.9.0:</p><p><strong>1-</strong> Open your Google account settings</p><p><strong>2-</strong> Click on the “2-Step Verification”</p><figure><img alt="gmail account settings" src="https://cdn-images-1.medium.com/max/1024/1*cMSLGYRz0aJ_OimbOdwdSQ.png" /></figure><p>then click on “Get Started” and enter your google password</p><figure><img alt="2 step varification" src="https://cdn-images-1.medium.com/max/1024/1*Q9uU8QcAE23bGGMGCW7V2Q.png" /></figure><p><strong>3-</strong> Verify your phone number</p><figure><img alt="verify phone number" src="https://cdn-images-1.medium.com/max/1024/1*VWWhV_6toWkmhTZYwY_cLw.png" /></figure><p>and click on “Turn On” 2 step verification</p><figure><img alt="turn on two step verification" src="https://cdn-images-1.medium.com/max/1024/1*t-GfxFpvaILhYWdTUxpTiw.png" /></figure><p><strong>4-</strong> After turning on the two-step verification turn back to the security section click on “App passwords” and enter your Google password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VV-6qEcICCrLlspuaZOUyg.png" /></figure><p><strong>5-</strong> Click on the select app dropdown and select other (Custom name)</p><figure><img alt="app password setting" src="https://cdn-images-1.medium.com/max/1024/1*V1nWLGV2qiP9CrquwzuUyg.png" /></figure><p><strong>6-</strong> Now type the name of your app/device</p><figure><img alt="app name / device name" src="https://cdn-images-1.medium.com/max/1024/1*rxNZW8pCpfh_BOONfBGCRQ.png" /></figure><p><strong>7-</strong> It will generate a 16-digit password and copy the password for later use</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BFLUcgDaVh66U1MFJgTYhQ.png" /></figure><p><strong>8-</strong> Open the .env file of your project</p><p><strong>9-</strong> Convert this:</p><blockquote>MAIL_MAILER=smtp</blockquote><blockquote>MAIL_HOST=smtp.mailtrap.io</blockquote><blockquote>MAIL_PORT=2525</blockquote><blockquote>MAIL_USERNAME=null</blockquote><blockquote>MAIL_PASSWORD=null</blockquote><blockquote>MAIL_ENCRYPTION=null</blockquote><blockquote>MAIL_FROM_ADDRESS=null</blockquote><blockquote>MAIL_FROM_NAME=”${APP_NAME}”</blockquote><p>With this:</p><blockquote>MAIL_MAILER=smtp</blockquote><blockquote>MAIL_HOST=smtp.gmail.com</blockquote><blockquote>MAIL_PORT=465</blockquote><blockquote>MAIL_USERNAME=your-gmail-account@gmail.com</blockquote><blockquote>MAIL_PASSWORD=your-app-password (16 digits)</blockquote><blockquote>MAIL_ENCRYPTION=ssl</blockquote><blockquote>#MAIL_FROM_ADDRESS=null</blockquote><blockquote>#MAIL_FROM_NAME=”${APP_NAME}”</blockquote><p>The Gmail SMTP is done and there is no need to change anything else.</p><blockquote>I hope it helps!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd317ae6a45a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>