<?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 Sandun Sameera on Medium]]></title>
        <description><![CDATA[Stories by Sandun Sameera on Medium]]></description>
        <link>https://medium.com/@sandunsameera25?source=rss-2f5a52fcd02c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*oxJL02EgZOOMhYj7.jpg</url>
            <title>Stories by Sandun Sameera on Medium</title>
            <link>https://medium.com/@sandunsameera25?source=rss-2f5a52fcd02c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 05:33:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sandunsameera25/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[Writing an API with endpoints in Laravel to insert data to mysql database.]]></title>
            <link>https://medium.com/@sandunsameera25/writing-an-api-with-endpoints-in-laravel-to-insert-data-to-mysql-database-18bca8b29e86?source=rss-2f5a52fcd02c------2</link>
            <guid isPermaLink="false">https://medium.com/p/18bca8b29e86</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[post-request]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[data-insertion]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Sandun Sameera]]></dc:creator>
            <pubDate>Sat, 14 Dec 2019 19:53:50 GMT</pubDate>
            <atom:updated>2019-12-14T19:53:50.665Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KkSthGV2Adw0JF6rDhpyrg.png" /></figure><p>Hello guys this is my first Medium article today lets learn how to write an API with endpoints in laravel so we can send HTTP request to perform desired task.</p><p><strong>Prerequisites:</strong></p><ol><li>I know that you are aware of what is an API. If not just click <a href="https://www.youtube.com/watch?v=tI8ijLpZaHk&amp;t=546s">here</a> and watch this video.</li><li>I assumed that you already installed laravel to your machine.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*WkzGyk6RCb0xKoDkNuSHCA.gif" /></figure><p><strong>Lets start</strong></p><p><strong>Step 1:</strong></p><p><strong>Create a fresh project</strong></p><p>First of all lets create fresh laravel project. So just fire up a terminal and paste composer create-project laravel/laravel your-project-name here you can choose any name for the project just type your preferred name instead of your-project-name. and open project with your editor</p><p><strong>Step 2:</strong></p><p><strong>Setup the .env file</strong></p><p>Now you can type command php artisan serve and see laravel default loading page. First of all lets setup .env file in folder structure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APtXfLCDeP5fkh4PPmH5Hw.png" /></figure><p>here change the name of the database to your database name.</p><p><strong>Step 3:</strong></p><p><strong>Lets start coding..!</strong></p><p><strong>Make a table</strong></p><p>So First of all lets create students table in our database. Creating a table is just bread and butter like thing in laravel. Just go to your terminal and type php artisan make:migration create_student_table after that command successfully executed you can see it under app/database/migrations. Before adding any columns to it you need to make a model fro that. You can do that using artisan make:make model student and it will appear under app folder.</p><p>So make your model as this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3wcSfabCepZ9-GxpNWaowQ.png" /></figure><p>and table like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8QYIWJw52pBrW5a8PfY_lw.png" /></figure><p>Now paste lets push this changes to database using php artisan migrate. and boom columns and all the things are migrated to database</p><p><strong>Step 4:</strong></p><p>Now go to the folder routes on your folder structure and there you can see a file named with api.php there lets define our api. In my case I will inset data to table student in my databse. You can define api address like this in api.php file Route::post(&#39;/InsertStudent&#39;,&#39;StudentController@insertstudent&#39;);</p><p>I know you are worried about where this StudentController part came from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*ozdqjQMi7wQyzIvtsKofEg.jpeg" /></figure><p>No worries so lets create our controller.</p><p><strong>Step 4:</strong></p><p><strong>Make a controller</strong></p><p>Making a controller is a super easy thing to do in laravel. You just want to go to the terminal and php artisan make:controller StudentController Once you done that you can see a controller made under app/Http/Controllers.</p><p>Now lets write the function to post our data to database. Paste this code under controller</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eS7DtGUziMZxC9pGiFxlkA.png" /></figure><p><strong>Remember to import that model we created and that</strong> is it lets try this with postman.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m9oGXQoez-fKVbazYJm6Bg.png" /></figure><p>Whooha !! So you can see we successfully got the json.</p><p>So guys this is it for this article see you with another soon. Until then see you later..!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18bca8b29e86" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>