<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: keikesu0122</title>
    <description>The latest articles on Forem by keikesu0122 (@keikesu0122).</description>
    <link>https://forem.com/keikesu0122</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F551632%2F3e950f07-4f82-4db3-bffd-d9f0992c1ba2.jpeg</url>
      <title>Forem: keikesu0122</title>
      <link>https://forem.com/keikesu0122</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/keikesu0122"/>
    <language>en</language>
    <item>
      <title>How does Composer help you manage php libraries?</title>
      <dc:creator>keikesu0122</dc:creator>
      <pubDate>Sun, 31 Jan 2021 12:56:54 +0000</pubDate>
      <link>https://forem.com/keikesu0122/how-does-composer-help-you-manage-php-libraries-488</link>
      <guid>https://forem.com/keikesu0122/how-does-composer-help-you-manage-php-libraries-488</guid>
      <description>&lt;p&gt;&lt;strong&gt;1.What is Composer?&lt;/strong&gt;&lt;br&gt;
Composer helps you manage php libraries. Let's assume that you want to use library A that depends on library B. Without Composer, you would need to install library A and B by hand. Meanwhile, if you use Composer to install library A, you don't care about library B because Composer automatically installs libraries required by library A.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.How to install Composer on Centos7&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add EPEL and REMI repositories
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum install epel-release

sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Install Composer
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum install --enablerepo=remi,remi-php73 php-pecl-zip composer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Check the Composer version to confirm that Composer has been property installed
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;3.How to install libraries using Composer&lt;/strong&gt;&lt;br&gt;
There are two ways to install libraries with Composer.&lt;br&gt;
Let's take the installation of monolog library as an example.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;composer require&lt;/code&gt;
Simply implement the following command to install monolog.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require monolog/monolog:"^2.0"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The library information consists of &lt;code&gt;vendor name/project name:version&lt;/code&gt;, which is recorded in &lt;code&gt;composer.json&lt;/code&gt;. With the command above, you can use monolog.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;composer install&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Add the following code in &lt;code&gt;composer.json&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"require": {
    "monolog/monolog": "^2.0"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Implement the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;composer install&lt;/code&gt; installs the libraries written in &lt;code&gt;composer.json&lt;/code&gt;. Now, you can use monolog.&lt;/p&gt;

&lt;p&gt;The installed libraries are stored in &lt;code&gt;/vendor&lt;/code&gt;, and you need to add &lt;code&gt;require("vendor/autoload.php");&lt;/code&gt; to your php program in order to use the libraries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.What is the difference among &lt;code&gt;composer require&lt;/code&gt;, &lt;code&gt;composer install&lt;/code&gt; and &lt;code&gt;composer update&lt;/code&gt;?&lt;/strong&gt;&lt;br&gt;
As mentioned earlier, &lt;code&gt;composer require&lt;/code&gt; is used to install a new library, and the installed library is recorded in &lt;code&gt;composer.json&lt;/code&gt;. &lt;code&gt;composer install&lt;/code&gt; installs the libraries in &lt;code&gt;composer.json&lt;/code&gt;, and their versions depend on the &lt;code&gt;composer.lock&lt;/code&gt;, which manages library versions. For example, if you want to install the libraries you're currently using onto a different development environment, you should copy &lt;code&gt;composer.json&lt;/code&gt; and &lt;code&gt;composer.lock&lt;/code&gt; and execute &lt;code&gt;composer install&lt;/code&gt; so that the same libraries will be installed there. &lt;code&gt;composer update&lt;/code&gt; is used to update the versions of the libraries recorded in &lt;code&gt;composer.json&lt;/code&gt;. Aforementioned, the version information is recorded in &lt;code&gt;composer.lock&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>php</category>
      <category>composer</category>
      <category>beginners</category>
    </item>
    <item>
      <title>An Introductory Explanation of NAT and NAPT</title>
      <dc:creator>keikesu0122</dc:creator>
      <pubDate>Sat, 16 Jan 2021 12:25:07 +0000</pubDate>
      <link>https://forem.com/keikesu0122/an-introductory-explanation-of-nat-and-napt-4h5p</link>
      <guid>https://forem.com/keikesu0122/an-introductory-explanation-of-nat-and-napt-4h5p</guid>
      <description>&lt;h1&gt;
  
  
  What is NAT?
&lt;/h1&gt;

&lt;p&gt;NAT stands for Network Address Transition. As the name suggests, NAT was developed to convert an IP address into a different one. NAT is mainly used to change a global IP into a private IP and vice versa. Let's take an example to understand how NAT works. Your PC has a private IP address (e.g. &lt;code&gt;192.168.10.xxx&lt;/code&gt;), and it is usable only in a local network such as your home network. If you use an Windows PC, you should enter &lt;code&gt;ipconfig&lt;/code&gt; on the command prompt to see the private IP assigned to your PC. When your PC attempts to access to the Internet, a global IP (e.g. &lt;code&gt;34.203.75.ZZZ&lt;/code&gt;) has to be assigned to it. This is where the NAT technique comes in. NAT assigns a global IP to your PC so that it can reach the Internet.&lt;/p&gt;

&lt;h1&gt;
  
  
  What problem does NAT have?
&lt;/h1&gt;

&lt;p&gt;NAT is not a perfect solution to get Internet access. Imagine that your PC (&lt;code&gt;192.168.1.xxx&lt;/code&gt;) and tablet (&lt;code&gt;192.168.1.YYY&lt;/code&gt;) attempt to get some data from the Internet at the same time. They have the same global IP on the Internet and it will be converted back into their each private IP by the router of your local network. Here is the problem. When the router tries to convert the global IP into a private IP, will the router convert it into the PC's private IP (&lt;code&gt;192.168.1.XXX&lt;/code&gt;) or the tablet's private IP (&lt;code&gt;192.168.1.YYY&lt;/code&gt;)? Since the global IP doesn't have information to distinguish your PC and table, the question is impossible to answer. Given this factor, NAT can not let multiple devices access the Internet simultaneously.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is NAPT?
&lt;/h1&gt;

&lt;p&gt;NAPT technique can solve the aforementioned problem. In addition to an IP address, NAPT also converts a port number. As I said above, you can not distinguish your PC and tablet only from the global IP. However, if different port numbers are assigned to your PC and tablet, let's say... &lt;code&gt;192.168.1.XXX:10000&lt;/code&gt; =&amp;gt; &lt;code&gt;34.203.75.ZZZ:20000&lt;/code&gt; (PC) and &lt;code&gt;192.168.1.YYY:10000 =&amp;gt; 34.203.75.ZZZ:30000&lt;/code&gt; (tablet), the router can clearly distinguish your PC and table, which makes it possible to let multiple devices reach the Internet simultaneously.&lt;/p&gt;

</description>
      <category>network</category>
      <category>web</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A simple way to create an SSL certificate with Let's Encypt</title>
      <dc:creator>keikesu0122</dc:creator>
      <pubDate>Sun, 10 Jan 2021 14:38:21 +0000</pubDate>
      <link>https://forem.com/keikesu0122/a-simple-way-to-create-an-ssl-certificate-with-let-s-encypt-2g68</link>
      <guid>https://forem.com/keikesu0122/a-simple-way-to-create-an-ssl-certificate-with-let-s-encypt-2g68</guid>
      <description>&lt;h1&gt;
  
  
  What is an SSL certificate?
&lt;/h1&gt;

&lt;p&gt;SSL, which stands for secure sockets layer, has two main roles. The first role is to acknowledge the validity of a web server. In other words, an SSL certificate ensures that the web server does exist. The second role is to encrypt between the web server and web clients. Without an SSL certificate, your credential information has a risk of being stolen because it is not encrypted. An SSL certificate ensures a safe communication on the Internet.&lt;/p&gt;

&lt;h1&gt;
  
  
  How does SSL secure the safety?
&lt;/h1&gt;

&lt;p&gt;1.A web client (browser) attempts to access a web server.&lt;/p&gt;

&lt;p&gt;2.The server sends its SSL certificate and public key to the browser.&lt;/p&gt;

&lt;p&gt;3.Checking the validity of the certificate, the browser creates a common key.&lt;/p&gt;

&lt;p&gt;4.Encrypting the common key with the public key, the browser sends the common key to the server.&lt;/p&gt;

&lt;p&gt;5.The server decrypts the encrypted common key and keeps it.&lt;/p&gt;

&lt;p&gt;After the process above, the communication between the server and browser is always encrypted with the common key.&lt;/p&gt;

&lt;h1&gt;
  
  
  How can you get an SSL certificate for your website?
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Let's Encrypt&lt;/code&gt; is an easy solution to create an SSL certificate&lt;/p&gt;

&lt;p&gt;1.Install the client software of &lt;code&gt;Let's Encrypt&lt;/code&gt;, or certbot&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ sudo yum install epel-release
 $ sudo yum install certbot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.Create an SSL certificate&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;certbot certonly --standalone -d www.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use the &lt;code&gt;--standalone&lt;/code&gt; option only when your web server such as apache and nginx is off. If you want to run this command with the web server on, you have to use the &lt;code&gt;--webroot&lt;/code&gt; option.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; $ certbot certonly --webroot -w /var/www/www.example.com -d www.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need to add the document root after the &lt;code&gt;-w&lt;/code&gt;.&lt;br&gt;
If you want to cover multiple domains, you can simply add the &lt;code&gt;-d&lt;/code&gt; option as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;certbot certonly --standalone -d www.example.com -d www2.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.Change your web server configuration&lt;/p&gt;

&lt;p&gt;You need to add the following configuration to &lt;code&gt;/etc/nginx/conf.d/default.conf&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 443 ssl;
    server_name www.example.com;
    root /var/www/www.example.com/current/web;
    ssl_certificate /etc/letsencrypt/live/www.example.com/privkey.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.example.com/fullchain.pem;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.Restart your web server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl restart nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, you can access to your website with HTTPS.&lt;/p&gt;

</description>
      <category>https</category>
      <category>ssl</category>
      <category>web</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to authenticate users on Laravel using middleware</title>
      <dc:creator>keikesu0122</dc:creator>
      <pubDate>Sat, 09 Jan 2021 15:17:49 +0000</pubDate>
      <link>https://forem.com/keikesu0122/how-to-authenticate-users-on-laravel-using-middleware-43a2</link>
      <guid>https://forem.com/keikesu0122/how-to-authenticate-users-on-laravel-using-middleware-43a2</guid>
      <description>&lt;p&gt;1.add a route for login&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::post('/login', 'auth@login');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.make a controller and method for login&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Util\authorizer;

class auth extends Controller
{
    public function __construct()
    {
        $this-&amp;gt;authorizer = new authorizer();
    }

    public function login(Request $request)
    {
        $id = $request-&amp;gt;post('userId');
        $pw = $request-&amp;gt;post('password');

        $this-&amp;gt;authorizer-&amp;gt;authUser($id, $pw);

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;authUser&lt;/code&gt; actually authenticates users, so the next step is to make this method.&lt;/p&gt;

&lt;p&gt;3.make a method to authenticate a user&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch app/Models/Utils/authorizer.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace App\Models\Util;

use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Model;
use Session;

class authorizer extends Model
{
    public function __construct()
    {
        $this-&amp;gt;users = new \App\Users();
    }

    //obtain a record from User table and verify the entered userId and password
    public function authUser($id, $pw)
    {
        if (is_null($id)) return false;
        if (is_null($pw)) return false;
        $user = $this-&amp;gt;users::where('userId',$id)-&amp;gt;get();
        if ($user === False) return false;
        if (count($user) == 0 || !isset($user['pw'])) return false;
        if (password_verify($pw, $user['pw'])) {
            $this-&amp;gt;setAuthSession($user);
        } 
    }

    // add userId to session
    private function setAuthSession($data)
    {
        if (isset($data['userId'])) request()-&amp;gt;session()-&amp;gt;put('userId', $data['userId']);
        request()-&amp;gt;session()-&amp;gt;save();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, a login function has been mounted. The next step is to distinguish unauthorized users from authorized users.&lt;/p&gt;

&lt;p&gt;4.make a middlerware&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:middleware Authentication
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace App\Http\Middleware;

use Closure;

class Authentication
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        //check the session information for auchentication
        if($request-&amp;gt;session()-&amp;gt;get('userId')==null){
            return response()-&amp;gt;json(array('status' =&amp;gt; 'NG'),403);
        }
        return $next($request);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5.add the middleware to Kernel.php to use it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        //'auth' =&amp;gt; \Illuminate\Auth\Middleware\Authenticate::class,
        'authentication' =&amp;gt; \App\Http\Middleware\Authentication::class,
        'auth.basic' =&amp;gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' =&amp;gt; \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' =&amp;gt; \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' =&amp;gt; \Illuminate\Auth\Middleware\Authorize::class,
        'guest' =&amp;gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
        'signed' =&amp;gt; \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' =&amp;gt; \Illuminate\Routing\Middleware\ThrottleRequests::class,
    ];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;add a route group to your route file
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::group(['middleware' =&amp;gt; ['authentication']], function () {
   Route::get('/userlist', 'users@getUserList');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By adding routes in the group, the middleware function (in this case &lt;code&gt;authentication&lt;/code&gt;) is implemented so that unauthorized users can't reach &lt;code&gt;/userlist&lt;/code&gt;.  &lt;/p&gt;

</description>
      <category>laravel</category>
      <category>login</category>
      <category>logout</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How do session and cookie work?</title>
      <dc:creator>keikesu0122</dc:creator>
      <pubDate>Sat, 09 Jan 2021 12:47:36 +0000</pubDate>
      <link>https://forem.com/keikesu0122/how-do-session-and-cookie-work-12b9</link>
      <guid>https://forem.com/keikesu0122/how-do-session-and-cookie-work-12b9</guid>
      <description>&lt;h1&gt;
  
  
  What is session?
&lt;/h1&gt;

&lt;p&gt;Session is used to identify a user and store the user information. When you first login to a certain web application, an unique session id is created and stored in the web server. For example, if you add an item to your cart on an EC website, this information is also added to the session. In this way, session consists of an unique id and other user-related information. When you visit the same website again, you can open your personal page without entering your name or password. That is because the session id is used to find out who you are.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is cookie?
&lt;/h1&gt;

&lt;p&gt;Web clients, web browsers in other words, also hold the session ids created in the web sites you have visited. The session ids stored in web browsers are called cookies.&lt;/p&gt;

&lt;h1&gt;
  
  
  How do they work?
&lt;/h1&gt;

&lt;p&gt;When you visit a website, your browser sends cookie information to the web server as a part of its http request. The web server finds the session id that matches with the cookie sent from your browser. Going through this process, the web server recognizes who is visiting the web site.&lt;/p&gt;

</description>
      <category>session</category>
      <category>cookie</category>
      <category>http</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A simple way to enable CORS on Laravel</title>
      <dc:creator>keikesu0122</dc:creator>
      <pubDate>Sun, 03 Jan 2021 15:48:08 +0000</pubDate>
      <link>https://forem.com/keikesu0122/a-simple-way-to-enable-cors-on-laravel-55i</link>
      <guid>https://forem.com/keikesu0122/a-simple-way-to-enable-cors-on-laravel-55i</guid>
      <description>&lt;h1&gt;
  
  
  What is CORS?
&lt;/h1&gt;

&lt;p&gt;CORS stands for Cross Origin Resource Sharing. Origin consists of protocol, domain and port number such as &lt;a href="https://hogehoge.com:443"&gt;https://hogehoge.com:443&lt;/a&gt;. Therefore, CORS means allowing an web application on a certain origin (e.g. &lt;a href="https://hogehoge.com"&gt;https://hogehoge.com&lt;/a&gt;) to access an web application on a different origin (e.g. &lt;a href="https://fugafuga.com"&gt;https://fugafuga.com&lt;/a&gt;).&lt;/p&gt;

&lt;h1&gt;
  
  
  Why is CORS necessary?
&lt;/h1&gt;

&lt;p&gt;In order to prevent cross site scripting (XSS) and cross site request forgeries, JavaScript's asynchronous communication such as Ajax follows the same origin policy, which bans access to a different origin. Without CORS configuration, web applications can not access a different origin.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is required to enable CORS?
&lt;/h1&gt;

&lt;p&gt;The simplest method to enable CORS is to add &lt;code&gt;Access-Control-Allow-Origin:*&lt;/code&gt; to the response header from WEB servers, which allows CORS from any source. If you want to limit the source, you should specify the domain in the configuration such as &lt;code&gt;Access-Control-Allow-Origin:https://hogehoge.com&lt;/code&gt;. You should note that a domain has to be specified if an http request includes cookie information.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to enable CORS on Laravel
&lt;/h1&gt;

&lt;p&gt;You can use an middleware that adds &lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt; to an http response header.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;create an middleware
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ php artisan make:middleware Cors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.Edit the middleware&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace App\Http\Middleware;

use Closure;

class Cors
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        return $next($request)
            -&amp;gt;header('Access-Control-Allow-Origin', '*')

    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.Add the middleware to Kernel.php&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected $routeMiddleware = [
        'auth'          =&amp;gt; \Illuminate\Auth\Middleware\Authenticate::class,
        'auth.basic'    =&amp;gt; \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings'      =&amp;gt; \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' =&amp;gt; \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can'           =&amp;gt; \Illuminate\Auth\Middleware\Authorize::class,
        'guest'         =&amp;gt; \App\Http\Middleware\RedirectIfAuthenticated::class,
        'signed'        =&amp;gt; \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle'      =&amp;gt; \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'cors'          =&amp;gt; \App\Http\Middleware\Cors::class, // added
    ];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.Set the middleware to routes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::middleware(['cors'])-&amp;gt;group(function () {
    Route::post('/hogehoge', 'Controller@hogehoge');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>http</category>
      <category>https</category>
      <category>beginners</category>
      <category>laravel</category>
    </item>
    <item>
      <title>A simple way to update your php to 8.0 on CentOS7</title>
      <dc:creator>keikesu0122</dc:creator>
      <pubDate>Sat, 02 Jan 2021 10:23:31 +0000</pubDate>
      <link>https://forem.com/keikesu0122/how-to-update-your-php-to-8-0-on-centos7-1blh</link>
      <guid>https://forem.com/keikesu0122/how-to-update-your-php-to-8-0-on-centos7-1blh</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Uninstall your current php and its modules
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum remove -y php php-*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Add remi repository
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Install php 8.0
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum install -y --enablerepo=remi-php80 php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Confirm the php version
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php -v
PHP 8.0.0 (cli) (built: Nov 24 2020 17:04:03) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5.Install necessary php modules&lt;/p&gt;

</description>
      <category>php</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
