<?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 Brice on Medium]]></title>
        <description><![CDATA[Stories by Brice on Medium]]></description>
        <link>https://medium.com/@brice.aminou?source=rss-78c50dc3f82d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*5ckZXUdTQ8Qep31R</url>
            <title>Stories by Brice on Medium</title>
            <link>https://medium.com/@brice.aminou?source=rss-78c50dc3f82d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 17:07:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@brice.aminou/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[Create a mobile app with Laravel PHP Framework]]></title>
            <link>https://medium.com/@brice.aminou/create-a-mobile-app-with-laravel-php-framework-3b1d91c0d66a?source=rss-78c50dc3f82d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b1d91c0d66a</guid>
            <category><![CDATA[laravel-framework]]></category>
            <category><![CDATA[mobile-apps]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Brice]]></dc:creator>
            <pubDate>Thu, 21 May 2020 00:56:58 GMT</pubDate>
            <atom:updated>2020-05-21T00:56:58.674Z</atom:updated>
            <content:encoded><![CDATA[<p>This tutorial describes an easy way to create a mobile app from your existing Laravel application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*Y-7yuW-NjJpdX0PaJzlDaQ.png" /></figure><p>Laravel is a free open-source PHP web Framework that helps you build web applications rapidly and efficiently using the model-view-controller (MVC) architectural pattern. To build a web application, Laravel is comparable to Django (Python) or Ruby on Rails (Ruby). The choice of the right Framework to use for your next application if you are not familiar with any of them depends on how comfortable you feel with PHP, Python or Ruby. In this post, we are only going to talk about Laravel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*Zb5uLBp121eccZsCmhGSmQ.png" /></figure><p>At the end of this tutorial, you will be able to create a hybrid app from an existing Laravel project. A hybrid app has many advantages if you are familiar with HTML, CSS and Javascript:</p><ul><li>The app can be published on the Play Store (iOS also, but it is not part of this tutorial)</li><li>There is no API to build so only one source code to manage</li><li>Works on any platform</li><li>Can access the features of a mobile phone like a native app</li></ul><p>This tutorial is using:</p><h3>Laravel Installation</h3><p>If you already have an existing project, you can jump directly to the next step.</p><p>SSH to your host and make sure that you have the permissions to edit the directory where your website is going to be hosted. If you do not have the permissions, ask your server administrator to give you the permissions.</p><p>Go to the Apache public directory (Usually /var/www/html, but might change depending on your apache setup)</p><pre>cd /var/www/html</pre><p>Create a new Laravel project. In this tutorial, we are going to use composer, but you can also use Laravel Installer <a href="https://laravel.com/docs/5.4/installation#installing-laravel">in their documentation</a>, the result is the same.</p><pre>composer create-project --prefer-dist laravel/laravel blog cd blog</pre><p>Change the owner of the following folders to let the apache user (often www-data) have read and write permissions.</p><pre>sudo chown -R www-data:www-data storage sudo chown -R www-data:www-data vendor</pre><p>Go to:</p><pre><a href="http://{your-domain-name}/">http://{YOUR-DOMAIN-NAME}</a></pre><p>And you should see the following example. If you don’t, check your Laravel installation or it might be a permission issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M1mppAOi9uDtEw0M.png" /></figure><h3>Integrate laravel-mobile-detect</h3><p>Go to your project root directory (/var/www/html) and run the following command:</p><pre>composer require riverskies/laravel-mobile-detect</pre><p>Open the file resources/views/welcome.blade.php An add the following lines before &lt;!DOCTYPE html&gt;:</p><p>Open <a href="http://{your-domain-name}/">http://{YOUR-DOMAIN-NAME}</a> on your desktop and you should see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7DeqknZ0x9CpshMH.png" /></figure><p>If you open the same page from your device or from <a href="https://developers.google.com/web/tools/chrome-devtools/device-mode/">Chrome’s simulation with google chrome</a>, you should see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*6PTxMjTHFyKypYz7.png" /></figure><h3>Build the mobile app</h3><p><a href="https://github.com/slymax/webview/archive/master.zip">Download Slymax Webview</a></p><p>Open Android Studio</p><p>Unzip the downloaded directory and open it in Android Studio</p><h3>Edit Slymax Webview template</h3><ul><li>Uncomment line 31 in MainActivity.java and replace <a href="http://example.com/">http://example.com</a> with your URL.</li><li>Uncomment line 34</li><li>Open MyAppWebViewClient.java and replace “example.com” with your domain name.</li></ul><p>Replace example.com with your domain URL.</p><p>Run the app on your mobile device or using an emulator and that’s it!</p><p>This is an easy way to create a mobile app from a Laravel application. Next thing would be to create two views, one for desktop and one for mobile. If you want to create a new app from a Laravel application, I would strongly suggest to look or build a responsive web app template using Phonegap, Cordova or Framework7 so you only have to create one unique view for your pages.</p><p><em>Originally published at </em><a href="https://softeng.oicr.on.ca/brice_aminou/2017/03/07/Mobile-app-with-Laravel/"><em>https://softeng.oicr.on.ca</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b1d91c0d66a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create a controller within Laravel]]></title>
            <link>https://medium.com/@brice.aminou/how-to-create-a-controller-within-laravel-6bb786a26069?source=rss-78c50dc3f82d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bb786a26069</guid>
            <category><![CDATA[laravel-5]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel-framework]]></category>
            <category><![CDATA[mvc-frameworks]]></category>
            <dc:creator><![CDATA[Brice]]></dc:creator>
            <pubDate>Tue, 19 May 2020 14:58:57 GMT</pubDate>
            <atom:updated>2020-05-19T14:58:57.410Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*2cG6jhlz7KmGx3WISznYsA.png" /></figure><p>If you use Laravel, you know that it is a MVC framework. A MVC framework is a framework that helps you build your platform using the MVC architecture. MVC stands for Model, View and Controller. In brief, users are interacting with the View, which sends requests to the Controller and the Controller sends request to update the database. As you see, the Controller is the place where we receive requests and save objects.</p><p>In this article, we will see how we can create a controller within Laravel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*Zb5uLBp121eccZsCmhGSmQ.png" /></figure><h3>Create a basic controller</h3><p>Open a terminal and go to the root of your project. Enter:</p><pre>php artisan make:controller PostController</pre><p>Then you can go under the folder app/Http/Controllers and you will see a new file called PostController.php.</p><h3>Create a CRUD Controller</h3><p>Many times, we are going to work with the CRUD model in our controller. That means that we want four methods.</p><ol><li>Create — A method where we can create new objects</li><li>Retrieve — A method that retrieves an object</li><li>Update — A method that updates an object</li><li>Delete — A method that deletes an object</li></ol><p>In order to create a controller with all those methods ready, you can type:</p><pre>php artisan make:controller PostController --resource</pre><h3>Create an API Controller</h3><p>The previous command creates 6 methods, so two other methods are needed only for route purposes. A create to display the creation form of your object and an edit method to edit an existing object. If we want to build an API, we don’t need those two methods. You can then generate the controller using the following command.</p><pre>php artisan make:controller PostController --api</pre><h3>Conclusion</h3><p>This was a brief explanation of how to create a controller within Laravel. Make sure to remember that controllers are unique in Laravel. Please leave a comments if that was helpful and if you want to learn how to create link your controller to your routes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bb786a26069" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sending push notifications to Expo in Laravel]]></title>
            <link>https://medium.com/@brice.aminou/sending-push-notifications-to-expo-in-laravel-15ae55026382?source=rss-78c50dc3f82d------2</link>
            <guid isPermaLink="false">https://medium.com/p/15ae55026382</guid>
            <category><![CDATA[laravel-5]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[expo]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[laravel-framework]]></category>
            <dc:creator><![CDATA[Brice]]></dc:creator>
            <pubDate>Fri, 15 May 2020 02:28:59 GMT</pubDate>
            <atom:updated>2020-05-15T02:28:59.385Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes, when we build mobile apps, we want to alert our users of an event happening on our platform. Since our users do not always have our app open, we send them push notifications to alert them. Push notifications are the notifications that you see when your phone is closed; “Facebook — You have a new friend request”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YMeTQ_kMMN4-Y_-D1FH9dA.jpeg" /></figure><p>We will see how to start sending push notifications to a mobile app built with expo using a Laravel backend. In brief, we are going to alert our users of an event that is happening on their account.</p><p>This article assumes that you are already familiar with:</p><ul><li>Laravel and you have an existing Laravel project</li><li>Laravel built-in notifications</li><li>Expo and you have an existing Expo project</li><li>React or React Native</li></ul><h3>Create a Laravel notification</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*Zb5uLBp121eccZsCmhGSmQ.png" /></figure><p>We are going to start by creating a Laravel notification to alert our user that their account has been activated. Open a terminal, go to the root of your project and enter:</p><pre>php artisan make:notification ActivateNotification</pre><p>If the folder app/Notifications do not exist, it is going to be created. In this folder, you should see the file ActivateNotification.php. We are not going to go in details about notifications, but this is the notification that is going to be triggered to alert the user.</p><h3>Connect Laravel to Expo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XdzzTKkAkYKOY0IT1daGLg.png" /></figure><p>We are going to install a library to manage the connection between Laravel and Expo. This connection includes what is needed to:</p><ul><li>Authenticate the user with the device to our Laravel project</li><li>Log out once the mobile user uninstall the app</li><li>Send notifications to an user on the mobile device</li></ul><p>We are going to install <a href="https://github.com/Alymosul/laravel-exponent-push-notifications">laravel-exponent-push-notifications</a> library. Open your terminal and go to the root of your project.</p><pre>composer require alymosul/laravel-exponent-push-notifications</pre><p>Open your .env file and enter:</p><pre>EXPONENT_PUSH_NOTIFICATION_INTERESTS_STORAGE_DRIVER=database</pre><p>Then publish and run the migration:</p><pre>php artisan vendor:publish --provider=&quot;NotificationChannels\ExpoPushNotifications\ExpoPushNotificationsServiceProvider&quot; --tag=&quot;migrations&quot;</pre><pre>php artisan migrate</pre><p>After running those commands:</p><ol><li>A new table should be created in your database. This table is the one that is going to be used to link a user to a device.</li><li>A new endpoint called `api/exponent/devices/subscribe` is added. You are going to have to call this endpoint to subscribe an user using Expo.</li><li>An unsubscribing endpoint is created called `api/exponent/devices/unsubscribe`. You always need to unsubscribe the user once the user logs out of your mobile app.</li></ol><h3>Add expo method to our notification object</h3><p>The next step is to add a method in our app/Notifications/ActivateNotification.php:</p><pre>&lt;?php<br>...<br>use NotificationChannels\ExpoPushNotifications\ExpoChannel;<br>use NotificationChannels\ExpoPushNotifications\ExpoMessage;</pre><pre>class ActivateNotification extends Notification{<br>    ...<br>    public function via($notifiable)<br>    {<br>        return [ExpoChannel::class];<br>    }</pre><pre>public function toExpoPush($notifiable)<br>    {        <br>        return ExpoMessage::create()<br>        -&gt;badge(1)<br>        -&gt;enableSound()<br>        -&gt;title(&quot;Account activated&quot;)<br>        -&gt;body(&quot;Your account has been activated&quot;);<br>    }<br>}</pre><p>This tells to notify the user via Expo and the info required to create the notification on Expo. Once that part has been added, you can simply notify your users as you used to in Laravel.</p><pre>$user-&gt;notify(new ActivateNotification($invoice));</pre><h3>Conclusion</h3><p>This article shows how to easily setup Expo notifications in your Laravel project. Leave comments if you are interested in knowing how to build the Expo part using React.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15ae55026382" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to write a policy in Laravel]]></title>
            <link>https://medium.com/@brice.aminou/how-to-write-a-policy-in-laravel-8e0b46c85405?source=rss-78c50dc3f82d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e0b46c85405</guid>
            <category><![CDATA[laravel-eloquent]]></category>
            <category><![CDATA[laravel-framework]]></category>
            <category><![CDATA[laravel-policies]]></category>
            <category><![CDATA[laravel-5]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Brice]]></dc:creator>
            <pubDate>Mon, 11 May 2020 19:56:35 GMT</pubDate>
            <atom:updated>2020-05-11T20:00:47.907Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*5no_F6-Ajy-zvhCnyQJgGg.jpeg" /></figure><p>Sometimes in Laravel, we want to make sure that a user is allowed to view, delete or update a model. There are multiple ways to secure a model, and in this article, we will see how to use Laravel policies to secure access to our models.</p><p>Here are few assumptions and briefs before going forward:</p><ul><li>You have an existing Laravel Project</li><li>We will create a model named Post</li><li>We assume that the user creating a post can delete, update and view this post, but now one else can unless the post is <a href="http://c/">published</a>.</li></ul><p>Let’s get started!</p><h3>Create the post model</h3><p>Go to the root of your directory and created a new Post model by entering</p><pre>php artisan make:model Post</pre><p>You can create it with a migration using “-m”.</p><p>After this step, a new file named Post.php should be created under your app folder.</p><p>In app/Post.php, make sure that you add the relationship with user:</p><pre>public function user(){<br>    return $this-&gt;belongsTo(User::class);<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*cSs89NAczIkXWX7GeOWfOQ.jpeg" /></figure><h3>Create the model policy</h3><p>Now you are ready to create the policy based on the user that created the post. Create the policy by going to your terminal in the root folder of your project and entering:</p><pre>php artisan make:policy PostPolicy --model=Post</pre><p>Now, a new folder might be created under your app folder called Policies. Under this folder, you will see a file name PostPolicy.php. This file contains the empty methods to view, update or delete a Post. What you have to do is to implement those methods with the required logic.</p><h4>Create a new post policy</h4><p>Our system might allow everyone to create a new post. In that case, not much logic is required. In file app/Policies/PostPolicy.php, complete the create method.</p><pre># $user: The user who wants to create a new post<br>public function create(User $user){<br>    return true;<br>}</pre><h4>View a post policy</h4><p>A user that created a new post probably wants to be able to view this post as well, but this post should never be available to other users unless it is published. In file app/Policies/PostPolicy.php, complete the view method.</p><pre>public function view(User $user, Post $post){<br>    if($post-&gt;is_published == true){<br>        return true;<br>    }</pre><pre>    return $post-&gt;user-&gt;id === $user-&gt;id;<br>}</pre><p>You can see that this method is going to return true if the post is published . If not, the post is going to check if the user requesting to see the post is the user who created the post. If yes, it’s going to return true, false otherwise.</p><h4>Update and delete policies</h4><p>You can now add update and delete policies to the post model the same way. Once those two have been added, you are ready to start using the policy.</p><h3>Register the policy</h3><p>The last step is to register the policy. If you do not register the policy, you cannot use it in your project. Open /app/Providers/AuthServiceProvider and add the following lines.</p><pre>&lt;?php</pre><pre>namespace App\Providers;</pre><pre>use App\Post;<br>use App\Policies\PostPolicy;</pre><pre>...</pre><pre>protected $policies = [<br>...<br>Post::class =&gt; PostPolicy::class,<br>...<br>];</pre><p>This file says that you want to protect the post model with the post policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*Zb5uLBp121eccZsCmhGSmQ.png" /></figure><h3>Conclusion</h3><p>Hopefully this was useful. If you want to know how to work with policies, or if you want to know more about different ways to secure your app, please leave a comment. It will be a pleasure to write more about the subject.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e0b46c85405" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>