<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>php &#8211; The SIGMA</title>
	<atom:link href="https://danushka96.github.io/sigma/index.php/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>https://danushka96.github.io/sigma/</link>
	<description>&#60;For Those Who Code/&#62;</description>
	<lastBuildDate>
	Sat, 02 Mar 2019 16:57:34 +0000	</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.1.1</generator>
	<item>
		<title>මොකක්ද මේ CodeIgniter කියන්නේ ?</title>
		<link>https://danushka96.github.io/sigma/index.php/2018/09/20/introduction-of-codeigniter/</link>
				<comments>https://danushka96.github.io/sigma/index.php/2018/09/20/introduction-of-codeigniter/#respond</comments>
				<pubDate>Thu, 20 Sep 2018 05:18:22 +0000</pubDate>
		<dc:creator><![CDATA[Gayan Sampath]]></dc:creator>
				<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">https://danushka96.github.io/sigma/?p=1314</guid>
				<description><![CDATA[<p><span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">2</span> <span class="rt-label rt-postfix">minutes</span></span> ආයුබෝවන් යාලුවනේ!  මේ ලිපියත් එක්ක පටන් ගන්න යන්නේ CodeIgniter කියන Framework එකත් එක්ක කොහොමද වැඩ කරන්නේ කියලා උගන්වන්න යන ලිපි මාලාවක්. මේ පාඩම් මාලාව පදනම් වෙන්නේ PHP එක්ක. ඒක හින්දා PHP ගැන Basic ටිකක් වත් දැනගෙන තිබුණොත් මේක ගොඩක් වැදගත් වෙයි.  ඒ වගේම HTML, CSS, JS ගැනත් පොඩි දැනුමක් තියෙන්න ඕන.<a class="moretag" href="https://danushka96.github.io/sigma/index.php/2018/09/20/introduction-of-codeigniter/"> Read more&#8230;</a></p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/09/20/introduction-of-codeigniter/">මොකක්ද මේ CodeIgniter කියන්නේ ?</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></description>
								<content:encoded><![CDATA[<span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">2</span> <span class="rt-label rt-postfix">minutes</span></span><p>ආයුබෝවන් යාලුවනේ!  මේ ලිපියත් එක්ක පටන් ගන්න යන්නේ <span>CodeIgniter</span> කියන Framework එකත් එක්ක කොහොමද වැඩ කරන්නේ කියලා උගන්වන්න යන ලිපි මාලාවක්. මේ පාඩම් මාලාව පදනම් වෙන්නේ PHP එක්ක. ඒක හින්දා PHP ගැන Basic ටිකක් වත් දැනගෙන තිබුණොත් මේක ගොඩක් වැදගත් වෙයි.  ඒ වගේම HTML, CSS, JS ගැනත් පොඩි දැනුමක් තියෙන්න ඕන. ඒ දේවල් වල ගැන දැනටමත් දන්න කෙනෙක් නම් මේ ලිපි Set එක මාර වැදගත් වෙයි. Web Application එකක් ලේසියෙන්ම හදා ගන්න.</p>
<p>හරි මේ ටික කියවන්න ඕන උඩින් කියපු Requirements නැති කට්ටිය. තියන කට්ටිය මේ ටික Skip කරගෙන ඉස්සරහට යමු. මම මේ කියන්න හදන්නේ ඔයාලට උඩදි කියපු Skills ටික හදා ගන්න පුළුවන් ක්‍රමයක්. ඒ තමයි W3School එක. මම එක එක Topic එකට අදාල Link එක මෙතනට දාන්නම්. අවශ්‍ය නම් ඒ ටික බලලා දැනුමක් එකතු කර ගන්න. (පිළිවෙලට බලාගෙන යන්න)</p>
<p><strong>HTML</strong><span> </span>: <a href="https://www.w3schools.com/html/">https://www.w3schools.com/html/</a></p>
<p><strong>CSS</strong><span> </span>: <a href="https://www.w3schools.com/css">https://www.w3schools.com/css</a></p>
<p><strong>JS : </strong><a href="https://www.w3schools.com/js/default.asp">https://www.w3schools.com/js/default.asp</a></p>
<p><strong>PHP : </strong><a href="https://www.w3schools.com/php/default.asp">https://www.w3schools.com/php/default.asp</a></p>
<p>හරි එහෙනම්අ පි මුලින්ම බලමු මොකක්ද මේ MVC architecture එක කියන්නේ කියලා.</p>
<h4><strong>ඇත්තටම මොකක්ද මේ </strong><strong>MVC architecture එක </strong><strong>කියන්නේ ?</strong></h4>
<p>MVC කියලා කෙටියෙන් කියන්නේ <strong>Model, View සහ Controller </strong>කියන වචන තුනට. මේ MVC කියන එක ගොඩක් වෙලාවට භාවිතා කරන්නේ User Interfaces හදන්න. මේක ගොඩක් Programming Languages වලදි භාවිතා කරනවා.<span> </span><a href="https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller">Wiki</a><span> </span>එකත් පොඩ්ඩක් බලන්න.</p>
<p><img class=" wp-image-796 aligncenter" src="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/main-qimg-3736ee98eff0c8148e2372d2b693f0ce-300x203.png" alt="" width="355" height="240" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/04/main-qimg-3736ee98eff0c8148e2372d2b693f0ce-300x203.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/04/main-qimg-3736ee98eff0c8148e2372d2b693f0ce.png 431w" sizes="(max-width: 355px) 100vw, 355px" /></p>
<p>මේ තුන එකතු වෙලා කරන්නේ මේ රූපයේ තියෙනවා වගේ වැඩක්. අපේ Browser එක Http Request එකක් හරහා Web Application එකේ Controller එකට කතා කරනවා. දැන් Controller එක කරන්නේ Model එකට කතා කරලා එතනින් Data ඉල්ලගෙන ඒ Data අවශ්‍ය විදියට හදලා HTML එකේ View එකක් හදනවා. මේ Model එකෙන් තමයි අපි Database එකත් එක්ක සම්බන්ධ වෙන්නේ.</p>
<p>ඔන්න ඔකට තමයි MVC architecture එක කියල කියන්නේ.ඔන්න ඔය දේ තමයි <span>CodeIgniter</span> කියන Framework  එකෙත් පාවිච්චි වෙන්නෙ..MVC architecture එක ගැන හොඳ Idea එකක් අති කියලා හිතනවා. අපි දැන් බලමු කොහොමද <span>CodeIgniter Install </span> කරගන්නෙ කියලා.</p>
<p>පොඩි දෙයයි කරන්න තියෙන්නේ ..පහල තියන Link  එකින් ගිහින් files  ටික download කරගෙන extract  කර ගන්න.</p>
<p><a href="https://www.codeigniter.com/" rel="noopener" target="_blank">               Download Codeigniter</a></p>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/tempsnip-300x135.png" alt="" width="711" height="320" class=" wp-image-1321 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/tempsnip-300x135.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/tempsnip-768x345.png 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/tempsnip-1024x460.png 1024w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/tempsnip.png 1346w" sizes="(max-width: 711px) 100vw, 711px" /></p>
<p>&nbsp;</p>
<p>හරි දැන් files  ටික text editer එකකින් Open කරලා බලුවොත් දැකගන්ට ගන්ට පුලුවන් Application  කියලා Folder එකකුයි, System කියලා Folder එකකුයි , user_guide කියලා Folder එකකුයි තව files ටිකකුයි තියනවා.ඔක තමයි වල codeigniter වල folder structure  එක.ඊලග පඩමෙන් අපි බලමු codeigniter වල folder structure  එක විස්තර සහිතව.අදට පාඩම නිමයි .ඊලග පාඩමත් සමගින් හමුවෙමු.හමෝටම සුබ දවසක්!</p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/09/20/introduction-of-codeigniter/">මොකක්ද මේ CodeIgniter කියන්නේ ?</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></content:encoded>
							<wfw:commentRss>https://danushka96.github.io/sigma/index.php/2018/09/20/introduction-of-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Laravel වලින් Database Migrations කරමු.</title>
		<link>https://danushka96.github.io/sigma/index.php/2018/09/17/laravel-database-migrations/</link>
				<comments>https://danushka96.github.io/sigma/index.php/2018/09/17/laravel-database-migrations/#respond</comments>
				<pubDate>Mon, 17 Sep 2018 18:24:22 +0000</pubDate>
		<dc:creator><![CDATA[Danushka Herath]]></dc:creator>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[migrations]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sinhala]]></category>

		<guid isPermaLink="false">https://danushka96.github.io/sigma/?p=1271</guid>
				<description><![CDATA[<p><span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">3</span> <span class="rt-label rt-postfix">minutes</span></span> Web Application එකක් හදද්දි අපිට අවශ්‍යම වෙන දෙයක් තමයි Migration එහෙම නැත්නම් Database එක්ක ගණුදෙනු කරන එක. Database එකක් නැතිව Web Application එකකින් ගොඩක් දුරට තේරුමක් වෙන්නේ නෑ. අද කතා කරන්න යන්නේ Laravel එක්ක Database Migrations වැඩ ටික කරගන්නේ කොහොමද කියලා&#8230;&#8230; වෙනදා වගේම කියන්න ඕන මේක ඔයා බලන පළවෙනි laravel<a class="moretag" href="https://danushka96.github.io/sigma/index.php/2018/09/17/laravel-database-migrations/"> Read more&#8230;</a></p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/09/17/laravel-database-migrations/">Laravel වලින් Database Migrations කරමු.</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></description>
								<content:encoded><![CDATA[<span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">3</span> <span class="rt-label rt-postfix">minutes</span></span><p>Web Application එකක් හදද්දි අපිට අවශ්‍යම වෙන දෙයක් තමයි Migration එහෙම නැත්නම් Database එක්ක ගණුදෙනු කරන එක. Database එකක් නැතිව Web Application එකකින් ගොඩක් දුරට තේරුමක් වෙන්නේ නෑ. අද කතා කරන්න යන්නේ Laravel එක්ක Database Migrations වැඩ ටික කරගන්නේ කොහොමද කියලා&#8230;&#8230;</p>
<p>වෙනදා වගේම කියන්න ඕන මේක ඔයා බලන පළවෙනි laravel post එක නම් අපේ අනිත් ලිපි Set එකත් <a href="https://danushka96.github.io/sigma/index.php/2018/04/10/web-application-with-laravel/">මෙතනින්</a> බලන්න.</p>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Why_Laravel-300x171.jpg" alt="" width="523" height="298" class=" wp-image-1273 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Why_Laravel-300x171.jpg 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Why_Laravel.jpg 700w" sizes="(max-width: 523px) 100vw, 523px" /></p>
<h2><span style="text-decoration: underline; color: #0000ff;"><strong>මූලික හැඳින්වීම</strong></span></h2>
<p>උඩ තියෙන Image එක කියන්නේ Why Laravel කියන ප්‍රශ්නෙට තියෙන උත්තර. ඒ කියන්නේ අනිත් PHP Frameworks එක්ක compare කරලා බලද්දි Laravel වල තියෙන විශේෂත්වය. ඒකෙ උඩින්ම තියෙන දෙයක් තමයි මේ Migrations කියන එක. ඒකට ගොඩක් specialty එකක් දීලා තියෙන්නේ ඒකෙන් ලොකු වැඩ ගොඩක් Simple විදියට කරගන්න අවස්ථාවක් තියෙන හින්දා.</p>
<p>සාමාන්‍යයෙන් අපි මොකක්ම හරි Web Application එකක් Laravel නැතිව වෙනත් විදියකින් හදනවා නම් අපි කරන්නේ අපේ Source Code එක වෙනම හදලා Database එක වෙනම හදලා මේ දෙක php වලින් Connect කරගන්න එකනේ. දැන් හිතන්න ඔය System එක තවත් කාට හරි දෙන්න ඕන වුණා කියලා. එතකොට අපිට සිද්ධ වෙනවා අපේ source code එකත් එක්ක SQL Server එකෙන් export කරගත්තු database file එකත් දෙන්න. ඊට පස්සේ මේ system එක ගන්න කෙනා ආපහු ඒ database එක import කරගන්න. මොකක්ම හරි Error එකක් ඇවිත් අර database file එක import වෙන්නේ නැති වුණොත් අපිට ආපහු ඒ file එක edit කරන එක ඇත්තටම අමාරු වැඩක්. මොකද ඒකෙ තියෙන්නේ generate වෙලා තියෙන code set එකක් නිසා.</p>
<p>තවත් ප්‍රශ්ණයක් තමයි අපි හදන Database එක වැඩ කරන්නේ Mysql නම් Mysql server එකක විතරයි. අපිට වෙනත් platform එකකට මාරු වෙන්න ඕන වුණොත් අපිට Database එක redesign කරන්නත් සිද්ධ වෙනවා.</p>
<h5><span style="color: #ff6600;"><strong>Laravel වල තියෙන විසඳුම මොකද්ද?</strong></span></h5>
<p>සරලවම මේ ප්‍රශ්ණෙට laravel වල තියෙන විසඳුම තමයි Database Migration කියන්නේ. ඒ කියන්නේ අපි Database එක හදන්නෙත් අපේ System එකට අදාල files වලමයි. එතකොට අපිට තවත් කෙනෙකුට System එක දෙනකොට දෙන්න තියෙන්නේ අපි හදලා තියෙන system file set එක විතරයි. ඊට පස්සේ artisan වල තියෙන migrate command එක භාවිතා කරලා ඕනම කෙනෙකුට තමන්ගේ db එක හදා ගන්න පුළුවන්.</p>
<p>දැන් අපි මුල ඉඳන් මේ වැඩේ කරන්න ඕන කොහොමද කියලා බලමු.</p>
<p>&nbsp;</p>
<h3 style="text-align: center;"><span style="color: #ff9900;">Migration File එකක් හදාගමු.</span></h3>
<p style="padding-left: 30px;">මෙහෙම migrate files generate කරගන්න අපි භාවිතා කරන්නේ command prompt/terminal එක. ඒක නිසා මුලින්ම ඔයාලගෙ project එක (අලුත් project එකක් වුණොත් හොඳයි) තියෙන directory එක ඇතුලෙ command prompt එක හරි terminal එක හරි open කරගන්න ඕන.</p>
<p style="padding-left: 30px;">ඊට පස්සේ එකෙ මේ command එක ගහන්න.</p>
<pre style="padding-left: 30px;">php artisan make:migration create_users_table</pre>
<p style="padding-left: 30px;">මෙකෙ create_users_table කියන්නේ අපේ migration file එකේ නම. මේකට ඔයාලට කැමති නමක් දෙන්න පුළුවන්. මම user table එකක් හදන්න යන නිසා මේක දානවා. මේ Command එක run වුණාට පස්සේ database/migrations folder එක ඇතුලෙ අලුතින් file එකක් හැදෙනවා. මේ file එක හැදෙන්නේ ඕනම database operation එකක් කරගන්න ගැලපෙන විදියට.</p>
<p style="padding-left: 30px;">හැබැයි අපි දැන් කරන්න හදන්නේ අලුතින් table එකක් හදා ගන්න එක. ඒ වැඩේට විතරක් ගැලපෙන විදියට අපේ migration file එක හදා ගන්න ඕන නම් මේ විදියට command එක වෙනස් කරලා දෙන්න පුළුවන්.</p>
<pre style="padding-left: 30px;">php artisan make:migration create_users_table --create=users
</pre>
<h3 style="text-align: center;"><span style="color: #ff9900;">Migration File Structure</span></h3>
<p style="padding-left: 30px;">දැන් අපි බලන්න හදන්නේ කලින් පියවරේදි අපි generate කරගත්ත migration file එකේ structure එක තියෙන්නේ කොහොමද කියලා. ඒකට මේ මම පොඩි Table එකක් හදා ගන්න පුළුවන් Migration file එකක් මේ විදියට ලියා ගන්නවා. මෙකෙ table name එක flights.</p>
<pre>&lt;?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateFlightsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('flights', function (Blueprint $table) {
            $table-&gt;increments('id');
            $table-&gt;string('name');
            $table-&gt;string('airline');
            $table-&gt;timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('flights');
    }
}

</pre>
<p style="padding-left: 30px;">මේකෙ දැන් ඔයාලට පේනවා ඇති up, down කියලා methods දෙකක් තියෙනවා. අපි up කියන method එක ඇතුලේ ලියන්නේ අලුතින් Table එකක්, column එකක්, නැත්නම් indexes Create කරන Queries. Down method එක ඇතුලේ ලියවෙන්නේ up method එක reverse කරන query set එක. දැන් අපි බලන්න හදන්නේ Migration commands කිහිපයක් කරගන්න විදිය.</p>
<h3 style="text-align: center;"><span style="color: #ff6600;">Migration Commands</span></h3>
<h4 style="padding-left: 30px;"><span style="color: #ff9900;">Migration File එකක් run කරගන්න විදිය</span></h4>
<pre class=" language-php" style="padding-left: 30px;"><code class=" language-php">php artisan migrate</code></pre>
<p style="padding-left: 30px;">මේ command එක හරහා අපි හදලා තියෙන Migration files ඔක්කොම ටික අපිට Database server එක ඇතුලෙ run කරගන්න පුළුවන්.</p>
<h4 style="padding-left: 30px;"><span style="color: #ff9900;">Run වුන migration එකක් rollback (ආපහු මුල් තත්වෙට) කරගන්න විදිය</span></h4>
<pre class=" language-php" style="padding-left: 30px;"><code class=" language-php">php artisan migrate:rollback</code></pre>
<p style="padding-left: 30px;">මේ command එකෙන් අපි අන්තිමට run කරපු migration files ටික හරහා සිද්ධ වුණ changes ටික reverse කරගන්න එහෙම නැත්නම් rollback කරගන්න පුළුවන්.</p>
<pre class=" language-php" style="padding-left: 30px;"><code class=" language-php">php artisan migrate:rollback --step=5</code></pre>
<p style="padding-left: 30px;">මේ විදියෙන් අපිට rollback කරන්න ඕන steps ගාන දෙන්න පුළුවන්&#8230;</p>
<pre class=" language-php" style="padding-left: 30px;"><code class=" language-php">php artisan migrate:reset</code></pre>
<p style="padding-left: 30px;">මේ Command එකෙන් අපේ Database එකට migration files වලින් වුණු හැම change එකක්ම අයින් වෙනවා..</p>
<pre class=" language-php" style="padding-left: 30px;"><code class=" language-php">php artisan migrate:refresh</code></pre>
<p style="padding-left: 30px;">මේකෙන් අපිට උඩින් කතා කරපු step දෙකක් එක command එකෙන් කරගන්න පුළුවන්. ඒ කියන්නේ Database එක reset කරගෙන migrations files ටික run කරගන්න එක.</p>
<pre class=" language-php" style="padding-left: 30px;"><code class=" language-php">php artisan migrate:fresh</code></pre>
<p style="padding-left: 30px;">මෙකෙන් කලින් කරපු වැඩේට ටිකක් සමාන වැඩක් කරගන්න පුළුවන්. හැබැයි මේකෙදි database එක reset වෙන්නේ නැතිව වෙන්නේ ඔක්කොම Tables ටික ඉස්සරලාම drop කරගන්න එක. ඊට පස්සේ Migration files ටික run කරගන්නවා.</p>
<p>ලිපිය තවත් දික් වෙලා Boring වෙන නිසා මම Database Queries ලියා ගන්න විදිය ගැන තවත් ලිපියකින් කතා කරන්නම්. මේ ලිපිය ගැන මොකක් හරි ප්‍රශ්ණයක් තියෙනවා නම් Comment එකක් දාන්න. අලුත් ලිපියකින් හමු වෙමු&#8230;..</p>
<p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/09/17/laravel-database-migrations/">Laravel වලින් Database Migrations කරමු.</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></content:encoded>
							<wfw:commentRss>https://danushka96.github.io/sigma/index.php/2018/09/17/laravel-database-migrations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
							</item>
		<item>
		<title>Laravel වලින් CRUD Operations කරමු.</title>
		<link>https://danushka96.github.io/sigma/index.php/2018/09/04/laravel-crud-operations/</link>
				<comments>https://danushka96.github.io/sigma/index.php/2018/09/04/laravel-crud-operations/#comments</comments>
				<pubDate>Mon, 03 Sep 2018 18:33:21 +0000</pubDate>
		<dc:creator><![CDATA[Danushka Herath]]></dc:creator>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[crud]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[laravel]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sinhala]]></category>

		<guid isPermaLink="false">https://danushka96.github.io/sigma/?p=1205</guid>
				<description><![CDATA[<p><span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">6</span> <span class="rt-label rt-postfix">minutes</span></span> මේ ලිපියෙන් කතා කරන්න බලාපොරොත්තු වෙන්නේ Laravel එක්ක පොඩි CRUD Application එකක් හදන විදිය ගැන. ඒ කියන්නේ Create, Read, Update, Delete කියන Basic Database Function 4 කරන විදිය ගැන. (https://github.com/Danushka96/laravelcrud) Laravel Install කරන විදිය Basic Application එකක් හදන විදිය ගැන බැලුවේ නැත්නම් මේ ලිපිය බලන්න Installing Laravel Basic Application in<a class="moretag" href="https://danushka96.github.io/sigma/index.php/2018/09/04/laravel-crud-operations/"> Read more&#8230;</a></p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/09/04/laravel-crud-operations/">Laravel වලින් CRUD Operations කරමු.</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></description>
								<content:encoded><![CDATA[<span class="rt-reading-time" style="display: block;"><span class="rt-label">Reading Time: </span> <span class="rt-time">6</span> <span class="rt-label rt-postfix">minutes</span></span><p>මේ ලිපියෙන් කතා කරන්න බලාපොරොත්තු වෙන්නේ Laravel එක්ක පොඩි CRUD Application එකක් හදන විදිය ගැන. ඒ කියන්නේ Create, Read, Update, Delete කියන Basic Database Function 4 කරන විදිය ගැන. <a href="https://github.com/Danushka96/laravelcrud">(https://github.com/Danushka96/laravelcrud)</a></p>
<p>Laravel Install කරන විදිය Basic Application එකක් හදන විදිය ගැන බැලුවේ නැත්නම් මේ ලිපිය බලන්න</p>
<ol>
<li><a href="https://danushka96.github.io/sigma/index.php/2018/04/11/install-laravel-homestead-custom/">Installing Laravel</a></li>
<li><a href="https://danushka96.github.io/sigma/index.php/2018/04/25/laravel-basic-application/">Basic Application in Laravel</a></li>
</ol>
<h2><span style="text-decoration: underline; color: #ff9900;"><strong>මූලික පියවර</strong></span></h2>
<p>මුලින්ම කරන්න ඕන අලුත් Laravel Project එකක් පටන් ගන්න එක. ඒකට මේ command prompt එකෙන් Application එක හදන්න අවශ්‍ය තැනට ගිහින් මේ Command එක Paste කරලා Enter කරන්න.</p>
<blockquote><p><span>composer </span><span class="hljs-keyword">create</span><span>&#8211;</span><span class="hljs-keyword">project</span><span> </span><span class="hljs-comment">&#8211;prefer-dist laravel/laravel crudApps</span></p></blockquote>
<p>පොඩි වෙලාවකින් අලුත් Project එකක් හැදිලා තියෙයි crudApps නමෙන්. දැන් කරන්න තියෙන් අලුතින් Database එකක් හදා ගන්න එක. ඒකට mysql Server එක on කරලා අලුතින් Database එකක් හදලා ඒකට අදාල Login Details ටික .env file එකේ දාලා Save කරගන්න.</p>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-300x130.png" alt="" width="360" height="156" class="alignnone wp-image-1210" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-300x130.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture.png 322w" sizes="(max-width: 360px) 100vw, 360px" /></p>
<p>හරි මූලිකම පියවර ඔය ටික හරියට කර ගත්තහම ඉවරයි.</p>
<h2><span style="text-decoration: underline; color: #ff9900;"><strong>දෙවන පියවර</strong></span></h2>
<p>මේ පියවරේදි අපි කරන්නේ Database එකත් එක්ක සම්බන්ධ වැඩ ටිකක්. ඒ කියන්නේ Model File එකකුයි Migration File එකකුයි හදා ගන්න එක. ඒකට මේ විදියට කරගෙන යන්න.</p>
<p>මුලින්ම Empty Migration File එකකයි Model File එකකයි හදාගෙන ඒක Edit කරගමු. ඒකට Command Prompt එකෙන් අපි හදා ගත්ත අලුත් Project Folder එක ඇතුලට ගිහින් මේ Command එක Type කරන්න.</p>
<blockquote><p>php artisan make:model student -m</p></blockquote>
<p>මේක run වුණාට පස්සේ බලා ගන්න පුළුවන් අලුතින් create_students_table.php file එකක් migration folder එක ඇතුලෙ හැදිලා තියෙනවා. App folder එක ඇතුලෙත් අලුතින් student.php file එකක් හැදිලා තියෙනවා. හරි දැන් මේ file 2 edit කරගමු.</p>
<p>මුලින්ම Migration File එක edit කරගන්න විදිය බලමු.</p>
<p>මම මේ Tutorial එකට පාවිච්චි කරන්නේ Student ලාගේ පොඩි Details ටිකක් තියා ගන්න පුළුවන් Table එකක්. Fields ටික <strong>FirstName, LastName, Address, Telephone </strong>කියන ඒවා. ඒවාට හරියන්න තමයි මම මේ Migration File එක හදා ගන්නේ.</p>
<p><strong>create_students_table.php</strong></p>
<pre>&lt;?php 
use Illuminate\Support\Facades\Schema; 
use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateStudentsTable extends Migration { 
/** 
* Run the migrations. 
* 
* @return void 
*/ 
public function up() 
{ 
Schema::create('students', function (Blueprint $table) { $table-&gt;increments('id');
            $table-&gt;string('firstname');
            $table-&gt;string('lastname');
            $table-&gt;string('address');
            $table-&gt;string('tp');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('students');
    }
}

</pre>
<p>මේ එකින් එක $table-&gt;string(&#8216;firstname&#8217;); වගේ දීලා තියෙන්නේ අපිට Table එකේ හදා ගන්න ඕන කරන Fields ටික.</p>
<p>මේ විදියට Code එක ලියාගත්තට පස්සේ මේ Script එක Database Server එකේ run කරවන්න ඕන. ඒකට මේ migrate command එක use කරන්න පුළුවන් මේ විදියට.</p>
<blockquote><p>php artisan migrate</p></blockquote>
<p>දැන් ඔයාලට phpmyadmin වලින් අලුතින් හදපු Database එක බැලුවොත් පෙනෙයි අලුත් Table 2ක් හැදිලා තියෙනවා. (migration table එකෙන් වෙන දේ ගැන කලින් ලිපි වලින් කතා කලා)</p>
<p>හරි දැන් බලමු Model File එක හදා ගන්නේ කොහොමද කියලා. ඒක මේ විදියට Code කරගන්න.</p>
<pre>&lt;?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class student extends Model
{
    protected $fillable = ['firstname', 'lastname','address','tp'];
}

</pre>
<p>මේ පියවරේ වැඩ ටික මෙතනින් ඉවරයි. දැන් අපිට ඉතිරි වෙලා තියෙන්නේ Views ටිකයි Controller එකකුයි හදා ගන්න.</p>
<h2><span style="text-decoration: underline; color: #ff9900;"><strong>තුන්වෙනි පියවර</strong></span></h2>
<p>මේකෙදි අපි කරන්නේ අපිට අවශ්‍ය Views ටික හදා ගන්න එක. නිකන් Html Code ලියන හින්දා පැහැදිලි කරන්න ඕන නැති වෙයි කියලා හිතනවා. ඒක හින්දා View ටිකේ Code ටික දාගෙන යන්නම්. මේ ටික resourses/views folder එකේ Save කරගන්න.</p>
<p><strong>index.blade.php</strong></p>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;CRUD Application&lt;/title&gt;

&lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css"&gt;
&lt;link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class="container"&gt;
&lt;div class = "card-panel teal lighten-2"&gt;&lt;h3 style="text-align: center"&gt;CRUD Application&lt;/h3&gt;&lt;/div&gt;


&lt;div class = "card-panel center"&gt;
&lt;div style="float: left"&gt;
&lt;a class="btn-floating btn-large waves-effect waves-light red" href="{{url('student/create')}}"&gt;&lt;i class="material-icons float-left green"&gt;add&lt;/i&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;table class="striped" style="margin-top: 50px"&gt;
&lt;tr&gt;
&lt;th&gt;First Name&lt;/th&gt;
&lt;th&gt;Last Name&lt;/th&gt;
&lt;th&gt;Address&lt;/th&gt;
&lt;th&gt;Telephone&lt;/th&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;/tr&gt;
@foreach($students as $student)
&lt;tr&gt;
&lt;td&gt;{{ $student-&gt;firstname }}&lt;/td&gt;
&lt;td&gt;{{ $student-&gt;lastname }}&lt;/td&gt;
&lt;td&gt;{{ $student-&gt;address }}&lt;/td&gt;
&lt;td&gt;{{ $student-&gt;tp }}&lt;/td&gt;
&lt;td&gt;
&lt;div class="row"&gt;&lt;div class="col"&gt;
&lt;a href="{{url('student/'.$student-&gt;id.'/edit')}}"&gt;&lt;button class="btn btn-small blue"&gt;Edit&lt;/button&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;div class="col"&gt;
&lt;form method="POST" action="{{route('student.destroy',$student-&gt;id)}}"&gt;
@csrf
@method('DELETE')
&lt;button type="submit" class="btn btn-small red"&gt;Delete&lt;/button&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
@endforeach
&lt;/tabel&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-1-300x140.png" alt="" width="519" height="242" class=" wp-image-1222 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-1-300x140.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-1-768x359.png 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-1.png 998w" sizes="(max-width: 519px) 100vw, 519px" /></p>
<p><strong>add.blade.php</strong></p>
<pre>&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;CRUD Application&lt;/title&gt;

        &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css"&gt;
        &lt;link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div class="container"&gt;
        &lt;div class = "card-panel teal lighten-2"&gt;&lt;h3 style="text-align: center"&gt;CRUD Application&lt;/h3&gt;&lt;/div&gt;


        &lt;div class = "card-panel center"&gt;
              &lt;div class="row"&gt;
                &lt;form class="col s12" method="POST" action="{{url('/student')}}"&gt;
                    @csrf
                  &lt;div class="row"&gt;
                    &lt;div class="input-field col s6"&gt;
                      &lt;i class="material-icons prefix"&gt;account_circle&lt;/i&gt;
                      &lt;input id="firstname" type="text" class="validate" name="firstname"&gt;
                      &lt;label for="firstname"&gt;First Name&lt;/label&gt;
                    &lt;/div&gt;
                    &lt;div class="input-field col s6"&gt;
                      &lt;i class="material-icons prefix"&gt;account_circle&lt;/i&gt;
                      &lt;input id="lastname" type="tel" class="validate" name="lastname"&gt;
                      &lt;label for="lastname"&gt;Last Name&lt;/label&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="input-field col s6"&gt;
                      &lt;i class="material-icons prefix"&gt;home&lt;/i&gt;
                      &lt;input id="address" type="text" class="validate" name="address"&gt;
                      &lt;label for="address"&gt;Address&lt;/label&gt;
                    &lt;/div&gt;
                    &lt;div class="input-field col s6"&gt;
                      &lt;i class="material-icons prefix"&gt;phone&lt;/i&gt;
                      &lt;input id="telephone" type="tel" class="validate" name="tp"&gt;
                      &lt;label for="telephone"&gt;Telephone&lt;/label&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;input type="submit" name="submit" class="btn blue right" value="Save"&gt;
                &lt;/form&gt;
              &lt;/div&gt;
        &lt;/div&gt;
        &lt;/div&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-2-300x151.png" alt="" width="485" height="244" class=" wp-image-1224 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-2-300x151.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-2-768x386.png 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-2-1024x514.png 1024w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-2.png 1049w" sizes="(max-width: 485px) 100vw, 485px" /></p>
<p><strong>edit.blade.php</strong></p>
<pre>&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;CRUD Application&lt;/title&gt;

        &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css"&gt;
        &lt;link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div class="container"&gt;
        &lt;div class = "card-panel teal lighten-2"&gt;&lt;h3 style="text-align: center"&gt;CRUD Application&lt;/h3&gt;&lt;/div&gt;


        &lt;div class = "card-panel center"&gt;
              &lt;div class="row"&gt;
                &lt;form class="col s12" method="POST" action="{{ route('student.update',$student-&gt;id) }}"&gt;
                    @csrf
                    @method('PUT')
                  &lt;div class="row"&gt;
                    &lt;div class="input-field col s6"&gt;
                      &lt;i class="material-icons prefix"&gt;account_circle&lt;/i&gt;
                      &lt;input id="firstname" type="text" class="validate" name="firstname" value="{{ $student-&gt;firstname }}"&gt;
                      &lt;label for="firstname"&gt;First Name&lt;/label&gt;
                    &lt;/div&gt;
                    &lt;div class="input-field col s6"&gt;
                      &lt;i class="material-icons prefix"&gt;account_circle&lt;/i&gt;
                      &lt;input id="lastname" type="tel" class="validate" name="lastname" value="{{ $student-&gt;lastname }}"&gt;
                      &lt;label for="lastname"&gt;Last Name&lt;/label&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="row"&gt;
                    &lt;div class="input-field col s6"&gt;
                      &lt;i class="material-icons prefix"&gt;home&lt;/i&gt;
                      &lt;input id="address" type="text" class="validate" name="address" value="{{ $student-&gt;address }}"&gt;
                      &lt;label for="address"&gt;Address&lt;/label&gt;
                    &lt;/div&gt;
                    &lt;div class="input-field col s6"&gt;
                      &lt;i class="material-icons prefix"&gt;phone&lt;/i&gt;
                      &lt;input id="telephone" type="tel" class="validate" name="tp" value="{{ $student-&gt;tp }}"&gt;
                      &lt;label for="telephone"&gt;Telephone&lt;/label&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;input type="submit" name="submit" class="btn blue right" value="Update"&gt;
                &lt;/form&gt;
              &lt;/div&gt;
        &lt;/div&gt;
        &lt;/div&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre>
<p><img src="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-3-300x157.png" alt="" width="449" height="235" class=" wp-image-1225 aligncenter" srcset="https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-3-300x157.png 300w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-3-768x401.png 768w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-3-1024x534.png 1024w, https://danushka96.github.io/sigma/wp-content/uploads/2018/09/Capture-3.png 1054w" sizes="(max-width: 449px) 100vw, 449px" /></p>
<p>මේ Views ටික හරියට හදා ගත්ත නම් ඊළඟ පියවරට යන්න පුළුවන්&#8230;..</p>
<h3><span style="text-decoration: underline; color: #ff9900;"><strong>සිව්වන පියවර</strong></span></h3>
<p>මේ පියවරේදි අපි කරන්නේ Controller එකක් හදා ගන්න එක. ඒකට මේ Command එක command prompt එකේ run කර ගන්න.</p>
<blockquote><p>php artisan make:controller studentController &#8211;resource</p></blockquote>
<p>මේ Command එකෙන් වෙන්නේ අපිට Model එකක් Control කරන්න අවශ්‍ය වෙන Function එක්ක Controller එකක් හැදෙන එක. දැන් ඒ File එක open කරලා මේ විදියට code කරගන්න.</p>
<pre>&lt;?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\student;

class studentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $students = student::all();
        // dd($students);
        return view('index',['students'=&gt;$students]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('add');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $studentnew = new student;
        $studentnew -&gt; firstname = $request -&gt; firstname;
        $studentnew -&gt; lastname = $request -&gt; lastname;
        $studentnew -&gt; address = $request -&gt; address;
        $studentnew -&gt; tp = $request -&gt; tp;
        $studentnew -&gt; save();
        return redirect('student/create')-&gt;with('status','saved');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $studentfind = student::findOrFail($id);
        return view('edit',['student'=&gt;$studentfind]);

    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        $studentfind = student::findOrFail($id);
        $studentfind -&gt; firstname = $request -&gt; firstname;
        $studentfind -&gt; lastname = $request -&gt; lastname;
        $studentfind -&gt; address = $request -&gt; address;
        $studentfind -&gt; tp = $request -&gt; tp;
        $studentfind -&gt; save();
        return redirect('student/'.$studentfind-&gt;id.'/edit')-&gt;with('status','updated!');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $studentfind = student::findOrFail($id);
        $studentfind -&gt; delete();
        return redirect('/student');
    }
}

</pre>
<p>මේ File එකේ තියෙන $studentfind, $studentnew වගේ ඒවා තමන්ට කැමති Variables දාගන්න පුළුවන්&#8230;</p>
<h3><span style="text-decoration: underline; color: #ff9900;"><strong>පස්වෙනි පියවර</strong></span></h3>
<p>දැන් අපිට කරන්න ඉතිරි වෙලා තියෙන්නේ අන්තිම පියවර. ඒ කියන්නේ දැන් කරන්න ඕන Route ටික හරියට Config කරගන්න එක. ඒක අපිට කරන්න පුළුවන් Routes/web.php කියන File එක මේ විදියට Edit කරගෙන.</p>
<pre>&lt;?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});
Route::resource('student','studentController');</pre>
<p>මේ ටික ඉවරයි කියන්නේ අපේ Application එක run කරලා බලන්න පුළුවන් තත්වෙක දැන් තියෙනවා. Command Prompt එකේ මේ Command එක ගහලා Artisan Server එක on කරගෙන http://localhost:8000/student කියන link එක Browser එකේ Load කරගන්න.</p>
<blockquote><p>php artisan serve</p></blockquote>
<p>Add/ Edit/ Delete කරලා බලන්න. අවුලක් තිබුණොත් Comment එකක් දාන්න&#8230;&#8230;</p>
<p>Complete Project Download From here: <a href="https://github.com/Danushka96/laravelcrud">https://github.com/Danushka96/laravelcrud</a></p>
<p>The post <a rel="nofollow" href="https://danushka96.github.io/sigma/index.php/2018/09/04/laravel-crud-operations/">Laravel වලින් CRUD Operations කරමු.</a> appeared first on <a rel="nofollow" href="https://danushka96.github.io/sigma/">The SIGMA</a>.</p>
]]></content:encoded>
							<wfw:commentRss>https://danushka96.github.io/sigma/index.php/2018/09/04/laravel-crud-operations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
							</item>
	</channel>
</rss>
