<?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 Hocine Saad on Medium]]></title>
        <description><![CDATA[Stories by Hocine Saad on Medium]]></description>
        <link>https://medium.com/@theHocineSaad?source=rss-1cea0783d172------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mpGlIedsfWkakBFQ2xjHHw.jpeg</url>
            <title>Stories by Hocine Saad on Medium</title>
            <link>https://medium.com/@theHocineSaad?source=rss-1cea0783d172------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:26:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@theHocineSaad/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Laravel Ask AI Directly from Exception pages]]></title>
            <link>https://medium.com/@theHocineSaad/laravel-ask-ai-directly-from-exception-pages-f5a049804e66?source=rss-1cea0783d172------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5a049804e66</guid>
            <category><![CDATA[laravel-framework]]></category>
            <category><![CDATA[laravel-packages]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Hocine Saad]]></dc:creator>
            <pubDate>Sat, 30 Aug 2025 18:01:20 GMT</pubDate>
            <atom:updated>2025-08-30T18:17:26.137Z</atom:updated>
            <content:encoded><![CDATA[<p>Lately, Laravel has introduced a “Copy as Markdown” button on the error page in version 12.25.0. When this button is clicked, a Markdown representation of the exception will be copied to the clipboard, which can be pasted into AI tools like ChatGPT or Claude.</p><p>I really liked this new feature, so I wanted to extend it even further. I made a PR that adds Ask AI buttons, which, when clicked, open ChatGPT or Claude in a new browser window with the Markdown representation of the exception pre-filled for instant troubleshooting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*BXTvFlMreQowgY2WR4w85A.png" /></figure><p>But Taylor Otwell closed it and commented that they are working on similar features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*tz4z509O4G4TNZw7FQQYgg.png" /></figure><p>Since it might take them some time to include it, I built a package that adds this feature. We can use it until they add it directly into Laravel: <a href="https://github.com/thehocinesaad/laravel-error-ai"><strong>https://github.com/thehocinesaad/laravel-error-ai</strong></a></p><p>Just install the package, and you should see a dropdown with two buttons: Ask ChatGPT and Ask Claude. I should mention that it requires at least Laravel version 12.25.0, as it is the version where they introduced the “Copy as Markdown” button.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5a049804e66" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Stability AI in Laravel]]></title>
            <link>https://medium.com/@theHocineSaad/using-stability-ai-in-laravel-2f32e21f9be9?source=rss-1cea0783d172------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f32e21f9be9</guid>
            <category><![CDATA[stability]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[stability-ai]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Hocine Saad]]></dc:creator>
            <pubDate>Fri, 17 Nov 2023 19:09:13 GMT</pubDate>
            <atom:updated>2023-11-17T19:09:13.146Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Stability AI Laravel" src="https://cdn-images-1.medium.com/max/872/1*LcuyThBOrBFFa7zJvy61zQ.png" /></figure><p>Stability AI is an AI company that develops open-source models, such as <a href="https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0">Stability Diffusion XL</a>, which is capable of generating high-quality, realistic images from text descriptions.</p><p>In addition to Stability Diffusion XL, Stability AI also develops other open-source models, such as Stable LM, a suite of language models that can generate text and code.</p><p>As of writing this article, they offer an API for their image generation models. In this post, we’ll explore how to seamlessly interact with their API in Laravel using a custom package that I developed.</p><p>Before we get started, I encourage you to have a look at their <a href="https://platform.stability.ai/docs/api-reference">documentation</a> and <a href="https://platform.stability.ai/account/keys">get an API key.</a></p><p>To get started you have to install the package, you can do so using composer:</p><pre>composer require thehocinesaad/stability-laravel</pre><p>Then you will need to add your Stability AI API key to the .env file:</p><pre>STABILIY_API_KEY=sk-fuYQ3VpweDSPu...</pre><p>After that, you can start interacting with the API:</p><pre>$response = Stability::generations()-&gt;textToImage(<br>    &#39;stable-diffusion-xl-1024-v1-0&#39;,<br>    [<br>        &#39;text_prompts&#39; =&gt; [<br>            [<br>                &#39;text&#39; =&gt; &#39;A lighthouse on a cliff&#39;,<br>                &#39;weight&#39; =&gt; 0.5<br>            ],<br>        ],<br>        &#39;samples&#39; =&gt; 1,<br>    ]<br>);<br><br>dd($response[&#39;artifacts&#39;][0][&#39;base64&#39;]);<br>// &quot;iVBORw0KGgoAAAANSUhEUgAABAAAAQACAIAAADwf7zUAAM8MmNhQlgAAzwya...&quot;<br>//// An image encoded in base64.</pre><p>Here is the resulting image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nHuXfVr8zw6bvQA-IGrl1Q.png" /></figure><p>If it is necessary, you can add additional HTTP headers (which the API supports) to requests by adding them to the .env file:</p><pre>STABILIY_ACCEPT_HEADER=image/png<br>STABILIY_ORGANIZATION=org-123456<br>STABILIY_CLIENT_ID=my-great-plugin<br>STABILIY_CLIENT_VERSION=1.2.1</pre><p>As of the current writing, the package supports all existing Stability AI API endpoints</p><ul><li>User Account and Balance</li><li>Engines List</li><li>Text-to-Image</li><li>Image-to-Image</li><li>Image-to-Image Upscale</li><li>Image-to-Image Masking</li></ul><p>For more usage examples, please visit the <a href="https://github.com/theHocineSaad/stability-laravel#usage">GitHub repository</a> of the package.</p><p>Feel free to give it a shot and let me know your thoughts, Stability AI gives some free credits for new users so you will have a chance to try it out without worrying about paying any money.</p><p>I also developed a version of this package for PHP, here is its <a href="https://github.com/theHocineSaad/stability-php">GitHub repository</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f32e21f9be9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel Soft Delete: The Ultimate Guide You Need To Read]]></title>
            <link>https://medium.com/@theHocineSaad/laravel-soft-delete-896e8eaac464?source=rss-1cea0783d172------2</link>
            <guid isPermaLink="false">https://medium.com/p/896e8eaac464</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[laravel-development]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[laravel-framework]]></category>
            <dc:creator><![CDATA[Hocine Saad]]></dc:creator>
            <pubDate>Fri, 16 Sep 2022 11:47:55 GMT</pubDate>
            <atom:updated>2022-09-16T13:40:17.905Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U8MD9HgpRZageF31.png" /></figure><h3>Introduction</h3><p>In this article, we will discuss everything about Laravel soft delete, what is it, and how to use it, but first, let me talk to you a little bit about a feature we all know, love, and use on our computers (if you want to pass this introduction, jump to the title <a href="#de72"><strong>Laravel Soft Delete</strong></a>).</p><p>When you delete a file on your computer, it will be gone but you still can find it in the recycle bin and of course, you can restore it.</p><p>So basically the deleted file is not actually removed from your computer, it’s invisible and marked as Deleted, and recycle bin is just a place that shows a list of files that are marked as Deleted.</p><p>Deleting a record in your application from the database is definitive, it’s gone forever, you can’t access it again and you can’t restore it, maybe you can use a backup but I think you got the idea.</p><p>What if a user accidentally deleted some data?</p><p>What if you want to give the user the ability to restore deleted data?</p><p>What if you want to keep users for a while after they deleted their accounts?</p><p>Soft delete is the solution, it implements exactly the same logic as the recycle bin from computers, so deleting records will be just marking them as deleted and not removing them from the database.</p><h3>Laravel soft delete</h3><p>The Laravel team had done great work providing a built-in feature to soft delete records, it’s implementation is as easy as just adding a new table column deleted_at and using a trait SoftDeletes on your model.</p><h3>How to use soft delete in Laravel</h3><p>We will see now how we can implement Laravel soft delete, it’s so easy, I promise.</p><p>For example, we have a Post model and we want to add the ability to restore deleted posts, let’s enable soft delete for this model.</p><h4>1. Soft delete trait: SoftDeletes</h4><p>The first step is to add the SoftDeletes trait to the model:</p><blockquote><em>Illuminate\Database\Eloquent\SoftDeletes</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf9249bee06544dc70b9edf957fba7fe/href">https://medium.com/media/cf9249bee06544dc70b9edf957fba7fe/href</a></iframe><h4>2. Soft delete migration</h4><p>As a second and last step, we have to add the deleted_at column to the posts table, we will use the softDeletes() helper method as the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5007f9a7319550decfe157b4d01ed720/href">https://medium.com/media/5007f9a7319550decfe157b4d01ed720/href</a></iframe><p>That’s it!</p><p>Now, when you call the delete method, instead of removing the record from the database, the deleted_at column will be filled with the current date and time and of course, that deleted record will always be excluded from all future query results just like if it&#39;s deleted for real.</p><h3>How to retrieve soft deleted records</h3><p>If we want to get a list of all soft deleted posts of a user, we can do it like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e01e20b5398ee4f7e033283d0f19af37/href">https://medium.com/media/e01e20b5398ee4f7e033283d0f19af37/href</a></iframe><p>As I said above, soft deleted records will always be excluded from query results, but if we want to include them for any reason, we can use withTrashed() :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fb7b381e14c80036dfb5d841dce44e4/href">https://medium.com/media/4fb7b381e14c80036dfb5d841dce44e4/href</a></iframe><h3>How to restore soft deleted records</h3><p>Easy, use the restore() method, it will simply set the deleted_at column to null :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e5383c6c4057989a8a3b58648d7f657/href">https://medium.com/media/0e5383c6c4057989a8a3b58648d7f657/href</a></iframe><p>You can use the trashed method to check if a record has been soft deleted:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a565e9c3a717ab09178fedb467e4109/href">https://medium.com/media/4a565e9c3a717ab09178fedb467e4109/href</a></iframe><h3>How to permanently delete a record</h3><p>If for any reason you want to permanently delete a record, you can use the forceDelete method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90a99ed98943c055c2399732a3a7d232/href">https://medium.com/media/90a99ed98943c055c2399732a3a7d232/href</a></iframe><h3>Pruning soft deleted records</h3><p>Soft deleting records for a long time will make your database full of unnecessary data, so it makes sense to periodically delete some of the soft deleted data, to do that you can use the Illuminate\Database\Eloquent\Prunable or Illuminate\Database\Eloquent\MassPrunable trait, the difference between the two is that the MassPrunable trait will delete records using mass-deletion queries, so the model events will not be dispatched.</p><p>After choosing and using one of the traits from above, add a prunable method that returns an Eloquent query builder which determines which records you would like to prune:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/113ca4064624dd7b916e45f54d5d93bd/href">https://medium.com/media/113ca4064624dd7b916e45f54d5d93bd/href</a></iframe><p>The last step is to schedule the model:prune in the App\Console\Kernel class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/573ec9137cc867a77bc052c94fe02c44/href">https://medium.com/media/573ec9137cc867a77bc052c94fe02c44/href</a></iframe><p>And you’re done.</p><p>If you want, for example, to delete the images associated with a post after being pruned, you can use the pruning method that is called just before the record is deleted:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61f2de221cb626b99950bbe4b193a7b9/href">https://medium.com/media/61f2de221cb626b99950bbe4b193a7b9/href</a></iframe><p><strong>Note: </strong>this method will not be invoked if you used the Illuminate\Database\Eloquent\MassPrunable trait.</p><figure><a href="https://medium.com/subscribe/@theHocineSaad"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ciZdPIQUy-8UBvOo.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=896e8eaac464" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel Telescope: Important Helpful Tool You Need to Know More About]]></title>
            <link>https://medium.com/@theHocineSaad/laravel-telescope-cb165d23796a?source=rss-1cea0783d172------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb165d23796a</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel-packages]]></category>
            <category><![CDATA[php-developers]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[laravel-framework]]></category>
            <dc:creator><![CDATA[Hocine Saad]]></dc:creator>
            <pubDate>Thu, 08 Sep 2022 17:13:42 GMT</pubDate>
            <atom:updated>2022-09-08T17:13:42.555Z</atom:updated>
            <content:encoded><![CDATA[<h4>Laravel Telescope is a very helpful tool for you as a Laravel developer while debugging your applications</h4><figure><img alt="Laravel Telescope" src="https://cdn-images-1.medium.com/max/1024/1*kiUcW48EpCdQgYSAvihQSg.png" /></figure><p>As developers, debugging apps is the task we do most of the time, and the essential part of it is accessing debug information, knowing what’s happening under the hood like seeing what queries are executed, knowing what commands are executed by your Laravel application will help you a lot to debug your application, and this is exactly what Laravel Telescope can do for you.</p><figure><img alt="Laravel Telescope" src="https://cdn-images-1.medium.com/max/1024/0*sI_DFbljh0vKgYZx" /></figure><h3>What is Laravel Telescope</h3><p>Laravel Telescope is a first party <a href="https://laravel.com/">Laravel</a> package, its creators described it as:</p><blockquote>An elegant debug assistant for the Laravel framework.</blockquote><p>And this is exactly what it is, it’s your assistant while developing and debugging Laravel applications, it collects the important things you need to have an eye on like requests, database queries, queued jobs… basically everything’s happening in your application in one beautiful place so you can access them easily.</p><p>Laravel Telescope can also be helpful while improving the performance of your application, for example using its Queries feature that shows you all the database queries that are executed on every request, such a thing can, for example, help you identify repetitive and unnecessary queries and fix them.</p><h3>Laravel Telescope Installation</h3><p>You can install it easily as any other Laravel package via <a href="https://getcomposer.org/">composer</a>:</p><pre>composer require laravel/telescope</pre><p>After installing it, you can publish its assets using the following command:</p><pre>php artisan telescope:install</pre><p>Finally, you have to run migrations to create the tables needed by Laravel Telescope:</p><pre>php artisan migrate</pre><p>That’s it, to access Laravel Telescope’s dashboard and start using it, visit /telescope.</p><h3>Laravel Telescope in the Production environment</h3><p>Now this dashboard is accessible only in the Local environment, if you try to access it in the Production environment, you will get a 403 FORBIDDEN error and that&#39;s because of the authorization gate defined in app/Providers/TelescopeServiceProvider.php and that&#39;s for sure a good thing, you don&#39;t want to let everyone access Laravel Telescope&#39;s dashboard.</p><figure><img alt="Laravel Telescope 403 forbidden" src="https://cdn-images-1.medium.com/max/1024/0*44q9VIjbvO0j1uGA" /></figure><p>To access the dashboard in a Production environment, edit the authorization gate in the way you want it to be, for example:</p><blockquote>app/Providers/TelescopeServiceProvider.php</blockquote><pre>protected function gate()<br>    {<br>        Gate::define(&#39;viewTelescope&#39;, function ($user) {<br>            return in_array($user-&gt;email, [<br>                &#39;<a href="/service/mailto:your@email.com">your@email.com</a>&#39;<br>            ]);<br>        });<br>    }</pre><p>Or maybe by users ID:</p><pre>protected function gate()<br>    {<br>        Gate::define(&#39;viewTelescope&#39;, function ($user) {<br>            return in_array($user-&gt;id, [<br>                1,<br>            ]);<br>        });<br>    }</pre><p>For more information about Laravel Telescope, visit <a href="https://laravel.com/docs/9.x/telescope#introduction">the official documentation</a>.</p><p>Here is their <a href="https://github.com/laravel/telescope">official repository</a> on GitHub.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb165d23796a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Heroku Is No Longer Free, Here Are The Best Alternatives]]></title>
            <link>https://medium.com/@theHocineSaad/heroku-is-no-longer-free-here-are-the-best-alternatives-1c22d814e51d?source=rss-1cea0783d172------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c22d814e51d</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[hosting]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Hocine Saad]]></dc:creator>
            <pubDate>Mon, 29 Aug 2022 19:21:57 GMT</pubDate>
            <atom:updated>2022-08-29T19:21:57.121Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vhMAgdyhcEz_8PdQlvhdhA.png" /></figure><p>Heroku is a famous PAAS (Platform as a service), it allows developers to deploy apps very easily and in various languages and frameworks.</p><p>Heroku is founded in 2007 by Orion Henry, James Lindenbaum, and Adam Wiggins and it’s now part of Salesforce after it’s been acquired in 2011.</p><p>Heroku is so popular because of its simplicity and useability, you can go from an app on your computer to a deployed app with a URL to send to friends or clients in a matter of minutes, you don’t have to care about the server and the infrastructure, Heroku will take care of that for you.</p><h3>Is Heroku free?</h3><p>At the date of writing this post, 27 August 2022, Heroku does have a free tier to be used for learning purposes and for non-commercial apps like your own personal projects.</p><h3>Is Heroku free forever?</h3><p>Seems like the answer is No.<br>Bob Wise, Heroku’s general manager, has posted a post on the official Heroku blog talking about the things that will be changed in the future, and one of the things is stopping offering free plans.</p><h3>Is Heroku no longer free?</h3><p>If you’re reading this after 28 November 2022, then yes Heroku stopped its free tier, also the inactive accounts (for over a year) will be deleted.</p><h3>Why Heroku is no longer free?</h3><p>Heroku is doing this move not because they are bad or they hate their clients, they mentioned that the reason for that decision is because of the fraud and abuse of the Heroku free product plans.</p><h3>Best Heroku alternatives</h3><p>Just after I heard the news of Heroku stopping their free plans, I started searching for some alternatives that offer a free plan, here are the ones I found:</p><ul><li><a href="https://render.com/pricing">Render</a></li><li><a href="https://railway.app/pricing">Railway</a></li><li><a href="https://fly.io/pricing">Fly</a></li><li><a href="https://northflank.com/pricing">Northflank</a></li><li><a href="https://qoddi.com/#pricing">Qoddi</a></li><li><a href="https://www.koyeb.com/pricing">Koyeb</a></li></ul><p>And here is a list I found of PAAS with free tiers: <a href="https://github.com/ripienaar/free-for-dev#paas">https://github.com/ripienaar/free-for-dev#paas</a></p><p>Thanks for reading and please if you tried the services mentioned in this article, share your experience in the comments.</p><p>Do you know any other alternatives?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c22d814e51d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Implement the Picture-in-Picture Feature on Any Website]]></title>
            <link>https://medium.com/@theHocineSaad/how-to-implement-the-picture-in-picture-feature-on-any-website-340b329b8d4b?source=rss-1cea0783d172------2</link>
            <guid isPermaLink="false">https://medium.com/p/340b329b8d4b</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webdev]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Hocine Saad]]></dc:creator>
            <pubDate>Mon, 29 Aug 2022 19:11:35 GMT</pubDate>
            <atom:updated>2022-08-30T09:12:16.135Z</atom:updated>
            <content:encoded><![CDATA[<h4>It’s a very cool feature to add to any website and it’s really easier to implement than you think.</h4><figure><img alt="picture-on-picture api" src="https://cdn-images-1.medium.com/max/1024/1*kJTv5vhBh2QC9Ll0IeVSfQ.png" /></figure><p>The Picture-in-Picture API is one of the newest features that has been added to some modern browsers, it gives websites the ability to create a floating video window that will be on top of all other windows which lets the user keep watching the video while he interacts with other websites and also other apps on his device.</p><p>In this article, we will implement the Picture-in-Picture from scratch using vanilla Javascript, but before we get started, have a look at what we are going to make through this article:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FtheHocineSaad%2Fembed%2Fpreview%2FrNdgWea%3Fdefault-tabs%3Djs%252Cresult%26height%3D600%26host%3Dhttps%253A%252F%252Fcodepen.io%26slug-hash%3DrNdgWea&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2FtheHocineSaad%2Fpen%2FrNdgWea&amp;image=https%3A%2F%2Fshots.codepen.io%2FtheHocineSaad%2Fpen%2FrNdgWea-512.jpg%3Fversion%3D1661503858&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/faec97da9ea8d803fa6967ecca745451/href">https://medium.com/media/faec97da9ea8d803fa6967ecca745451/href</a></iframe><p>Let’s start with the HTML part, we just need a Video tag and a button that will enable and disable the Picture-in-Picture feature:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/125f70814ecb7915dc76c9981caeff9a/href">https://medium.com/media/125f70814ecb7915dc76c9981caeff9a/href</a></iframe><p>For the Javascript part, let’s first get our Video and Button:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f61f3a90239674fb2835bfaa43499f24/href">https://medium.com/media/f61f3a90239674fb2835bfaa43499f24/href</a></iframe><p>Next, since this feature is new and it’s not compatible with all browsers (at the date of writing this article), we have to check if the current browser supports it or not, let’s add some javascript:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6340851d56ad2bff411a987420841309/href">https://medium.com/media/6340851d56ad2bff411a987420841309/href</a></iframe><p>Now we can add an on-click event listener to the button that will enable Picture-in-Picture feature, but before that, we have to show and enable the button, because, as you can see in HTML, the button is Hidden and Disabled by default:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfbc980cacaf178a84edebc6cfb373b1/href">https://medium.com/media/bfbc980cacaf178a84edebc6cfb373b1/href</a></iframe><p>Now, our PIP feature is working, we just need to click on the button to enable it, let’s make the button dynamic, click on it to enable it, and if clicked again it will disable it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97cb7bbc9cb8c74b7f70c90c78dd4309/href">https://medium.com/media/97cb7bbc9cb8c74b7f70c90c78dd4309/href</a></iframe><p>We used document.pictureInPictureElement to check if there is an element on the page that uses PIP, if there is, document.exitPictureInPicture() will make the PIP element go back to its original format (a normal video) if there isn&#39;t then we simply enable PIP on the video.</p><p>Our PIP feature is working just fine, we can enable it and disable it just by clicking on the button, but we have one last thing to do, the text on the button is Enable Picture-in-Picture when we click on it and the PIP is enabled, the text should be Disable Picture-in-Picture right? let&#39;s do this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf95e70847cf23e06921c8f4f2b1cb4b/href">https://medium.com/media/cf95e70847cf23e06921c8f4f2b1cb4b/href</a></iframe><p>enterpictureinpicture and leavepictureinpicture are two useful events defined by the Picture-in-Picture API, they do exactly what their names say.</p><ul><li><strong><em>enterpictureinpicture </em></strong>will be triggered when PIP is enabled.</li><li><strong><em>leavepictureinpicture </em></strong>will be triggered when PIP is disabled.</li></ul><p>That’s it! Go try it yourself.</p><p>Picture-in-Picture API is still in its early days so it’s not supported by all browsers, make sure to use it very carefully.</p><figure><img alt="Can I use picture-on-picture" src="https://cdn-images-1.medium.com/max/1024/0*m4UwwCU4MvJZs2Jw" /></figure><blockquote><a href="https://caniuse.com/picture-in-picture">Can I use</a> .. 25 August 2022</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=340b329b8d4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel Passwordless Login, aka Magic Login links]]></title>
            <link>https://medium.com/@theHocineSaad/laravel-passwordless-login-magic-login-links-ffcd1a49bb9?source=rss-1cea0783d172------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffcd1a49bb9</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel-framework]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Hocine Saad]]></dc:creator>
            <pubDate>Mon, 29 Aug 2022 19:00:29 GMT</pubDate>
            <atom:updated>2022-08-29T19:00:29.933Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Laravel passwordless login" src="https://cdn-images-1.medium.com/max/1024/1*68t8nOqXkWzmR8nfFmFqQQ.png" /></figure><p>Laravel Passwordless Login, Magic Login Links, or simply letting users login without providing a password are all different terms of one login mechanism that works like this:</p><ol><li>The user enters his email/phone number.</li><li>The user submits the form.</li><li>An email/SMS will be sent to the user.</li><li>The user clicks on the link sent in the email/SMS</li><li>The user is logged in</li></ol><p>Simple yet efficient!</p><p>This flow of authentication is beneficial for both sides:</p><ul><li>For users, the experience will be much better because they will only need to provide their email address or phone number to register and to log in, no need to remember the password, in the same time, such thing will increase the security because we all know how weak are the passwords.</li><li>For developers and website owners, they will stop worrying about managing passwords which is not a simple task to do.</li></ul><p>In this article, we will implement this method of authentication on a Laravel 9 application, we will start from scratch, from the creation of a fresh Laravel application to generating and sending the login URL via email.</p><p>Let’s start by creating a new Laravel application using <a href="https://getcomposer.org/">Composer</a>:</p><pre>composer create-project laravel/laravel passwordless-login-app</pre><p>Jump inside the project’s folder:</p><pre>cd passwordless-login-app</pre><p>Open the project in the IDE you prefer and let’s start by configuring the connection to the database in the .env file:</p><pre>DB_CONNECTION=mysql<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=passwordless_login_app_db<br>DB_USERNAME=root<br>DB_PASSWORD=</pre><p>Before we run the migrations, we have some edits to do, first if you open the migration that creates users table:</p><blockquote>database/migrations/2014_10_12_000000_create_users_table.php</blockquote><p>You will find out that it contains a column for a password, since we are not going to need passwords, we can delete it:</p><pre>Schema::create(&#39;users&#39;, function (Blueprint $table) {<br>            $table-&gt;id();<br>            $table-&gt;string(&#39;name&#39;);<br>            $table-&gt;string(&#39;email&#39;)-&gt;unique();<br>            $table-&gt;timestamp(&#39;email_verified_at&#39;)-&gt;nullable();<br>            // $table-&gt;string(&#39;password&#39;); &lt;&lt; delete this line<br>            $table-&gt;rememberToken();<br>            $table-&gt;timestamps();<br>        });</pre><p>Let’s not forget to remove the password attribute from User Model’s $fillable array:</p><blockquote>app/Models/User.php</blockquote><pre>protected $fillable = [<br>        &#39;name&#39;,<br>        &#39;email&#39;,<br>        // &#39;password&#39;, &lt;&lt; delete this line<br>    ];</pre><p>Next, let’s delete the migration that creates the password resets table:</p><blockquote>database/migrations/2014_10_12_100000_create_password_resets_table.php</blockquote><p>We can now run our migrations:</p><pre>php artisan migrate</pre><p>Since we’re going to send the login URL via email, we need to configure our application to be able to send emails, I’ll use <a href="https://mailtrap.io/">Mailtrap</a>, let’s open our .env and start editing:</p><pre>MAIL_MAILER=smtp<br>MAIL_HOST=smtp.mailtrap.io<br>MAIL_PORT=2525<br>MAIL_USERNAME=YOUR_MAIL_USERNAME<br>MAIL_PASSWORD=YOUR_MAIL_PASSWORD<br>MAIL_ENCRYPTION=tls</pre><p>At this point, we can start working on the flow itself, we will use a package called <a href="https://github.com/grosv/laravel-passwordless-login">laravel-passwordless-login</a>.</p><p>Let’s install it:</p><pre>composer require grosv/laravel-passwordless-login</pre><p>Now we need two routes, the first one is for the page where the user can enter his email address, and the second one will handle the form submission.</p><p>Let’s add them:</p><blockquote>routes/web.php</blockquote><pre>use App\Http\Controllers\AuthController;<br><br><br>Route::get(&#39;/login&#39;, [AuthController::class, &#39;loginForm&#39;])-&gt;name(&#39;login&#39;);<br>Route::post(&#39;/login&#39;, [AuthController::class, &#39;sendLoginLink&#39;])-&gt;name(&#39;loginPost&#39;);</pre><p>Let’s create the AuthController that we used in the routes:</p><pre>php artisan make:controller AuthController</pre><p>AuthController will have two functions, here is the the whole controller:</p><pre>&lt;?php<br><br>namespace App\Http\Controllers;<br><br>use App\Models\User;<br>use Grosv\LaravelPasswordlessLogin\LoginUrl;<br>use Illuminate\Http\Request;<br>use Illuminate\Support\Facades\Mail;<br><br>class AuthController extends Controller<br>{<br><br>    function loginForm()<br>    {<br>        return view(&#39;auth.login&#39;);<br>    }<br><br>    function sendLoginLink(Request $request)<br>    {<br>        $user = User::whereEmail($request[&#39;email&#39;])-&gt;first();<br><br>        $generator = new LoginUrl($user);<br>        $url = $generator-&gt;generate();<br><br>        $content = &quot;&lt;a href=&quot; . $url . &quot;&gt;&quot; . $url . &quot;&lt;/a&gt;&quot;;<br>        Mail::html($content, fn ($message) =&gt; <br>            $message-&gt;to($request[&#39;email&#39;])<br>                -&gt;subject(&quot;Your magic login link&quot;)<br>                -&gt;from(&quot;email@example.com&quot;)<br>        );<br><br>        return view(&#39;auth.login&#39;, [&#39;emailIsSent&#39; =&gt; true]);<br>    }<br>}</pre><p>Let’s talk about what’s inside it, first, we have the loginForm function which simply returns a view where the user can enter his email, here is how it looks:</p><figure><img alt="Sign in form with Email only" src="https://cdn-images-1.medium.com/max/1024/0*EziY3WsLPEjNPfu5" /></figure><p>Create that view called login in resources/views/auth</p><blockquote>resources/views/auth/login.blade.php</blockquote><p>And here is its code:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot; class=&quot;h-full bg-gray-50&quot;&gt;<br><br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;<br>    &lt;title&gt;Login&lt;/title&gt;<br>&lt;/head&gt;<br><br>&lt;body class=&quot;h-full&quot;&gt;<br>    &lt;div class=&quot;min-h-full flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8&quot;&gt;<br>        &lt;div class=&quot;max-w-md w-full space-y-8&quot;&gt;<br>            @if (isset($emailIsSent))<br>            &lt;h2 class=&quot;mt-6 text-center text-3xl tracking-tight font-bold text-gray-900&quot;&gt;The magic login link has been sent to your email!&lt;/h2&gt;<br>            @else<br>            &lt;h2 class=&quot;mt-6 text-center text-3xl tracking-tight font-bold text-gray-900&quot;&gt;Sign in to your account&lt;/h2&gt;<br>            &lt;form class=&quot;mt-8 space-y-6&quot; action=&quot;{{ route(&#39;loginPost&#39;) }}&quot; method=&quot;POST&quot;&gt;<br>                @csrf<br>                &lt;div class=&quot;rounded-md shadow-sm -space-y-px&quot;&gt;<br>                    &lt;div&gt;<br>                        &lt;label for=&quot;email-address&quot; class=&quot;sr-only&quot;&gt;Email address&lt;/label&gt;<br>                        &lt;input id=&quot;email-address&quot; name=&quot;email&quot; type=&quot;email&quot; autocomplete=&quot;email&quot; required<br>                            class=&quot;appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm&quot;<br>                            placeholder=&quot;Email address&quot;&gt;<br>                    &lt;/div&gt;<br>                &lt;/div&gt;<br><br><br>                &lt;div&gt;<br>                    &lt;button type=&quot;submit&quot;<br>                        class=&quot;group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500&quot;&gt;<br>                        &lt;span class=&quot;absolute left-0 inset-y-0 flex items-center pl-3&quot;&gt;<br>                            &lt;!-- Heroicon name: solid/lock-closed --&gt;<br>                            &lt;svg class=&quot;h-5 w-5 text-indigo-500 group-hover:text-indigo-400&quot;<br>                                xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;0 0 20 20&quot; fill=&quot;currentColor&quot;<br>                                aria-hidden=&quot;true&quot;&gt;<br>                                &lt;path fill-rule=&quot;evenodd&quot;<br>                                    d=&quot;M5 9V7a5 5 0 0110 0v2a2 2 0 012 2v5a2 2 0 01-2 2H5a2 2 0 01-2-2v-5a2 2 0 012-2zm8-2v2H7V7a3 3 0 016 0z&quot;<br>                                    clip-rule=&quot;evenodd&quot; /&gt;<br>                            &lt;/svg&gt;<br>                        &lt;/span&gt;<br>                        Sign in<br>                    &lt;/button&gt;<br>                &lt;/div&gt;<br>            &lt;/form&gt;<br>            @endif<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;/body&gt;<br><br>&lt;/html&gt;</pre><p>Very simple, the only thing I have to explain here, is the $emailIsSent variable, I used it just so I can use one view for two purposes, if the variable $emailIsSent is not set, the page will contain a form where the user can enter his email, if it is set then the page will show a message that says the magic login link is sent ($emailIsSent will be set in the sendLoginLink function after we send the login link), I think you got it.</p><p>In the second function, which is sendLoginLink, we find the user by the email from the request:</p><pre>$user = User::whereEmail($request[&#39;email&#39;])-&gt;first();</pre><p>Then, using the package we installed (laravel-passwordless-login), we generate a magic login link:</p><pre>$generator = new LoginUrl($user);<br>$url = $generator-&gt;generate();</pre><p>After generating the login link, we send it to the user via email:</p><pre>$content = &quot;&lt;a href=&quot; . $url . &quot;&gt;&quot; . $url . &quot;&lt;/a&gt;&quot;;<br>        Mail::html($content, fn ($message) =&gt; <br>            $message-&gt;to($request[&#39;email&#39;])<br>                -&gt;subject(&quot;Your magic login link&quot;)<br>                -&gt;from(&quot;email@example.com&quot;)<br>);</pre><p>Finally, we return the login view with the emailIsSent variable which means the view will show a message that says the magic login link is sent:</p><pre>return view(&#39;auth.login&#39;, [&#39;emailIsSent&#39; =&gt; true]);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MCvfkmxtSaNZZZIH" /></figure><p>The user clicks on the link sent in email and he will be logged in!</p><p>To try, make sure to create a test user:</p><pre>php artisan tinker<br>User::create([&#39;name&#39;=&gt;&#39;test user&#39;, &#39;email&#39;=&gt;&#39;test@test.com&#39;])</pre><p>To edit where the user is redirected after he clicks on the login link, give a value to LPL_REDIRECT_ON_LOGIN in .env, its default value is / (LPL_REDIRECT_ON_LOGIN=/).</p><p>For more configurations and information, visit the page of the package on Github: <a href="https://github.com/grosv/laravel-passwordless-login">Laravel-Passwordless-Login</a>.</p><p>Thank you for reading ❤</p><p>What do you think this flow of authentication ?<br>Are you already using it ?<br>Will you use it in your future projects ?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffcd1a49bb9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Is “Laravel Pint” And Do I Need It As a Laravel Developer?]]></title>
            <link>https://medium.com/@theHocineSaad/what-is-laravel-pint-and-do-i-need-it-as-a-laravel-developer-5034f39e2de2?source=rss-1cea0783d172------2</link>
            <guid isPermaLink="false">https://medium.com/p/5034f39e2de2</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[laravel-framework]]></category>
            <dc:creator><![CDATA[Hocine Saad]]></dc:creator>
            <pubDate>Mon, 29 Aug 2022 18:32:52 GMT</pubDate>
            <atom:updated>2022-08-29T18:32:52.234Z</atom:updated>
            <content:encoded><![CDATA[<h4>YES, you do need Laravel Pint, do you think the Laravel team was stupid when they included it in all new Laravel applications?</h4><figure><img alt="Laravel Pint Logo" src="https://cdn-images-1.medium.com/max/1024/1*XTJDK6j301pMsD0lggxDbA.png" /></figure><p>Okay, let me start with the real reason why you are here…</p><h3>What Is Laravel Pint?</h3><p>Here is how the Laravel team describes it:</p><blockquote>Laravel Pint is an opinionated PHP code style fixer for minimalists. Pint is built on top of PHP-CS-Fixer and makes it simple to ensure that your code style stays clean and consistent.</blockquote><p>Laravel Pint is a tool that fixes your code to follow standards, in other words, it scans your entire code, detects coding standards problems, and fixes them for you in seconds, how cool is that!</p><p>Let’s have a look at it in action…</p><figure><img alt="PHP code" src="https://cdn-images-1.medium.com/max/707/1*obWOEK_p5pGSOzDqZdvvkw.jpeg" /></figure><p>That’s definitely not a piece of code that you would like to be on your computer, but let’s be honest, it happens sometimes.</p><p>Some things need to be changed in this code like long array syntax, double quotes, and the extra blank space.</p><p>Let’s see how Laravel Pint will fix that for you…</p><figure><img alt="PHP code" src="https://cdn-images-1.medium.com/max/684/1*V_09fFNRfgC0q8MTuiJovw.jpeg" /></figure><p>With one command, Laravel Pint made your code perfect!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kgmDk6NfC-ajOWW6uka9SQ.jpeg" /></figure><p>It also shows you how many files have been scanned, which files fixed, and the errors it fixed, what do you want more than that ?!</p><h3>How to install Laravel Pint?</h3><p>Let me stop you just right there, if you think installing it is hard and takes hours then you’re wrong.</p><p>In fact, if you are using a new Laravel application then my friend Laravel Pint is already installed and you just need to run it.</p><p>If it’s not installed in your project yet, then one command is all that you need to install it.</p><pre>composer require laravel/pint --dev</pre><h3>How to use Laravel Pint: Running Pint</h3><p>To simply run Laravel Pint to scan and fix all the files, use this command:</p><pre>./vendor/bin/pint</pre><p>To view more details about what Laravel Pint is changing in your files, provide the -v option:</p><pre>./vendor/bin/pint -v</pre><p>If you would like Laravel Pint to only scan your files and show you style errors without fixing them (without editing files), provide the --test option:</p><pre>./vendor/bin/pint --test</pre><h3>How to configure Laravel Pint?</h3><p>Laravel Pint doesn’t need any configuration to be used, you can install it and directly use it without thinking about configuring it.</p><p>However, if you want to use a different preset, tweak the rules, or customize inspected folders, you can do that by creating a pint.json file in the root directory of your project.</p><h3>Presets</h3><p>Presets are the groups of rules that Laravel Pint follows to detect and fix the code style issues in your code.</p><p>By default, Laravel Pint uses the Laravel preset but you still can choose the one you want using the pint.json file:</p><pre>{<br>    &quot;preset&quot;: &quot;psr12&quot;<br>}</pre><p>If you wish, you can also specify a different preset by providing the --preset option:</p><pre>./vendor/bin/pint --preset psr12</pre><p>At the time of writing this article, Laravel Pint supports three presets: laravel, psr12, and symfony.</p><h3>Rules</h3><p>Rules are the actual guidelines that Laravel Pint uses to fix your code.</p><p>Presets are groups of Rules that should be perfect for most of your projects, but if you would like to tweak some rules, you can do that using the pint.json file:</p><pre>{<br>    &quot;preset&quot;: &quot;laravel&quot;,<br>    &quot;rules&quot;: {<br>        &quot;simplified_null_return&quot;: true,<br>        &quot;braces&quot;: false,<br>        &quot;new_with_braces&quot;: {<br>            &quot;anonymous_class&quot;: false,<br>            &quot;named_class&quot;: false<br>        }<br>    }<br>}</pre><p><strong>Since Laravel Pint is built on top of </strong><a href="https://github.com/FriendsOfPHP/PHP-CS-Fixer"><strong>PHP-CS-Fixer</strong></a><strong>, you can use any of its rules: </strong><a href="https://mlocati.github.io/php-cs-fixer-configurator"><strong>PHP-CS-Fixer Configurator</strong></a><strong>.</strong></p><h3>Excluding Files / Folders</h3><p>By default, Laravel Pint will scan all .php files in your project (except the ones in the vendor directory), if you want to exclude more folders, you can use the exclude configuration option in the pint.json file:</p><pre>{<br>    &quot;exclude&quot;: [<br>        &quot;path/to/your-folder&quot;<br>    ]<br>}</pre><p>Want to exclude all files that contain a given name pattern? use the notName configuration option:</p><pre>{<br>    &quot;notName&quot;: [<br>        &quot;*-your-cool-file.php&quot;<br>    ]<br>}</pre><p>Want to exclude an exact file? use the notPath configuration option:</p><pre>{<br>    &quot;notPath&quot;: [<br>        &quot;path/to/your-file.php&quot;<br>    ]<br>}</pre><h3>Do you need Laravel Pint?</h3><p>After showing you what exactly it is and what it can do, I’ll let you answer that question.</p><p>For me though, I see it as a must install tool for every project, I definitely will use it for all my upcoming projects.</p><p>Will you use Laravel Pint?<br>Are you already using it?<br>Any thoughts you want to add?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5034f39e2de2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>