tag:blogger.com,1999:blog-50657578839071284162024-02-19T22:10:26.683+05:30Laravel TutorialsLearn the fastest php framework laravel.Laravel is a free, open source PHP web application framework, designed for the development of model–view–controller (MVC) web applications.Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-5065757883907128416.post-45255101457152002132015-04-10T18:31:00.001+05:302015-04-10T18:31:03.009+05:30Database connection in laravel<div dir="ltr" style="text-align: left;" trbidi="on">
This post is about creating a database connection in laravel.Connecting to database is quite simple and you need not take any pain in the process.So lets start.Before we create a connection to database we need a create so lets first create a database.If you know this step you can skip this process.I will be using CMD to create a database example with table users having fields id auto increment,name varchar,country varchar.<br />
I'm attaching a screen shot of my CMD.Please preview it by clicking on it since it is appearing small.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxA5I8x0MGpEssHUTe5ZuAbkPnvPDM9u5_S_yriPrD4FwU0-486JXWPGAFvWC6thm_RqaWJ09c6BVdlfPKTwHRMfS9T14TTXtpKkqH0Go0Ikpk1krGKYM7vDTwUs5KJABUo2Yjt7Pf6Rc/s1600/learn-laravel.blogspot.in+laravel+tutorials+5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxA5I8x0MGpEssHUTe5ZuAbkPnvPDM9u5_S_yriPrD4FwU0-486JXWPGAFvWC6thm_RqaWJ09c6BVdlfPKTwHRMfS9T14TTXtpKkqH0Go0Ikpk1krGKYM7vDTwUs5KJABUo2Yjt7Pf6Rc/s1600/learn-laravel.blogspot.in+laravel+tutorials+5.jpg" height="400" width="375" /></a></div>
<br />
<br />
<br />
Ignore the errors which i got while executing the queries :p<br />
Now lets create a connection to this database go to app/config and open database.php.Search for this block of code<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOUZYK7Uqh4rz0cPTYWUOyS5qf6O4xBXkr3dfU9hRveiPkLF-NYzlciRSYFfIXfR0PlseBpDnN77uu2JvHNwTEGuoBuXOwGnJHpOr0sjyo1AmQ372G7vnD9ps-GwAA0pmU4sui6qvye2o/s1600/learn-laravel.blogspot.in+laravel+tutorials+6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOUZYK7Uqh4rz0cPTYWUOyS5qf6O4xBXkr3dfU9hRveiPkLF-NYzlciRSYFfIXfR0PlseBpDnN77uu2JvHNwTEGuoBuXOwGnJHpOr0sjyo1AmQ372G7vnD9ps-GwAA0pmU4sui6qvye2o/s1600/learn-laravel.blogspot.in+laravel+tutorials+6.jpg" height="177" width="400" /></a></div>
<br />
<br />
<div style="text-align: left;">
Change the DB_DATABASE to example,DB_USERNAME to root,DB_PASSWORD to root.(Yours credentials may defer )</div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh78pb4N2TZD5ayqA8YgKXIdCDTCDyi5DZOGAT2ImLn0aJIJjrElIa6FEGjaFEvLlKnT7Upxyuv4Fu33ApV97hYxoYfQUdP9LKHuPxwPnvMKgPkHmpL9MToDeYw_RBgL-fJY6n-YpCeHQQ/s1600/learn-laravel.blogspot.in+laravel+tutorials+7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh78pb4N2TZD5ayqA8YgKXIdCDTCDyi5DZOGAT2ImLn0aJIJjrElIa6FEGjaFEvLlKnT7Upxyuv4Fu33ApV97hYxoYfQUdP9LKHuPxwPnvMKgPkHmpL9MToDeYw_RBgL-fJY6n-YpCeHQQ/s1600/learn-laravel.blogspot.in+laravel+tutorials+7.jpg" height="183" width="400" /></a></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Thats all folks and we are done with database connectivity :)</div>
</div>
Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.com6tag:blogger.com,1999:blog-5065757883907128416.post-86278014426037277832015-04-10T12:56:00.000+05:302015-04-10T12:56:01.709+05:30Get and Post request in laravel<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
This post is about handling GET and POST request in Laravel.But before we start you should be familiar with <a href="http://learn-laravel.blogspot.in/2015/03/basics-of-routing-in-laravel.html" target="_blank">Routing in Laravel</a>.Because routing is the most fundamental part in laravel.Since this is a step by step series I suggest you to read amy previous post if you find anything confusing....So let's get started.<br />
To understand GET and POST request in laravel we will be creating a simple form with Name and Password field.We will submit this form using both GET and POST method so that things become clear :)<br />
Before we start building our form we must create a route to our form.Open routes.php and create the following route</div>
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f8f8f2;">Route::get(</span><span style="color: #e6db74;">'form'</span><span style="color: #f8f8f2;">,function(){</span>
<span style="color: #66d9ef;">return</span> <span style="color: #f8f8f2;">View::make(</span><span style="color: #e6db74;">'form'</span><span style="color: #f8f8f2;">);</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
We have created a simple route without any parameters to form.blade.php view which holds our form<br />
Create form.blade.php and create a simple form<br />
<br />
<br /></div>
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f92672;"><</span><span style="background-color: #1e0010; color: #960050;">!</span><span style="color: #f8f8f2;">DOCTYPE</span> <span style="color: #f8f8f2;">html</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">html</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">head</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">title</span><span style="color: #f92672;">></</span><span style="color: #f8f8f2;">title</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">head</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">body</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">form</span> <span style="color: #f8f8f2;">method</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"get"</span> <span style="color: #f8f8f2;">action</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"verify_form"</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">label</span><span style="color: #f92672;">></span><span style="color: #f8f8f2;">Name</span><span style="color: #f92672;"></</span><span style="color: #f8f8f2;">label</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">input</span> <span style="color: #f8f8f2;">type</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"text"</span> <span style="color: #f8f8f2;">name</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"uname"</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">label</span><span style="color: #f92672;">></span><span style="color: #f8f8f2;">Password</span><span style="color: #f92672;"></</span><span style="color: #f8f8f2;">label</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">input</span> <span style="color: #f8f8f2;">type</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"password"</span> <span style="color: #f8f8f2;">name</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"pass"</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">input</span> <span style="color: #f8f8f2;">type</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"submit"</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">form</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">body</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">html</span><span style="color: #f92672;">></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
Simple HTML form with method as get and action set to verify_form.If you try to submit the form now you will get errors since we have not create a route to verify_form view.Open routes.php and create a route to verify_form.blade.php<br />
<br /></div>
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f8f8f2;">Route::get(</span><span style="color: #e6db74;">'verify_form'</span><span style="color: #f8f8f2;">,function(){</span>
<span style="color: #66d9ef;">return</span> <span style="color: #f8f8f2;">View::make(</span><span style="color: #e6db74;">'verify_form'</span><span style="color: #f8f8f2;">);</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
Now since we have created a route to verify_form view we will just verify if our form is working by just printing the variable using $_POST[] method of php.<br />
Open verify_form file and type in the following 2 lines<br />
<br />
<br /></div>
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f8f8f2;">Name:</span> <span style="color: #f8f8f2;">{{</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">_GET[</span><span style="color: #e6db74;">'uname'</span><span style="color: #f8f8f2;">]}}</span><span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">></span>
<span style="color: #f8f8f2;">Password:</span> <span style="color: #f8f8f2;">{{</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">_GET[</span><span style="color: #e6db74;">'pass'</span><span style="color: #f8f8f2;">]}}</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
Output<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3tGrTtWDcdX9_v2YYqpJhpgwYzgkvqm7Osmn_feAAGm1AU2Kpb_f4REp0IFS7m4MqGEciU2QhhWjC7zBdhsgZEo3bZTEUtttA4mx8CrnojDmHOEg2iLZzRwsKOmJJu3wKTB7Ma3ZdObU/s1600/learn-laravel.blogspot.in+laravel+tutorials+4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3tGrTtWDcdX9_v2YYqpJhpgwYzgkvqm7Osmn_feAAGm1AU2Kpb_f4REp0IFS7m4MqGEciU2QhhWjC7zBdhsgZEo3bZTEUtttA4mx8CrnojDmHOEg2iLZzRwsKOmJJu3wKTB7Ma3ZdObU/s1600/learn-laravel.blogspot.in+laravel+tutorials+4.jpg" height="235" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
So our routes and all other methods are working properly...Remember GET is not the best method when you are dealing with sensitive data as you can see that uname and pass variable can be seen in the URL of the browser.</div>
<div class="separator" style="clear: both; text-align: left;">
Coming to POST method the code almost remains the same except few changes like form method becomes post,Instead of get route we will create post route and we will grab the variable in verify_form using $_POST[] method</div>
<div class="separator" style="clear: both; text-align: left;">
form.blade.php file</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f92672;"><</span><span style="background-color: #1e0010; color: #960050;">!</span><span style="color: #f8f8f2;">DOCTYPE</span> <span style="color: #f8f8f2;">html</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">html</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">head</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">title</span><span style="color: #f92672;">></</span><span style="color: #f8f8f2;">title</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">head</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">body</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">form</span> <span style="color: #f8f8f2;">method</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"post"</span> <span style="color: #f8f8f2;">action</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"verify_form"</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">label</span><span style="color: #f92672;">></span><span style="color: #f8f8f2;">Name</span><span style="color: #f92672;"></</span><span style="color: #f8f8f2;">label</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">input</span> <span style="color: #f8f8f2;">type</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"text"</span> <span style="color: #f8f8f2;">name</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"uname"</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">label</span><span style="color: #f92672;">></span><span style="color: #f8f8f2;">Password</span><span style="color: #f92672;"></</span><span style="color: #f8f8f2;">label</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">input</span> <span style="color: #f8f8f2;">type</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"password"</span> <span style="color: #f8f8f2;">name</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"pass"</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">input</span> <span style="color: #f8f8f2;">type</span><span style="color: #f92672;">=</span><span style="color: #e6db74;">"submit"</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">form</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">body</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">html</span><span style="color: #f92672;">></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
routes.php file<br />
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f8f8f2;">Route::post(</span><span style="color: #e6db74;">'verify_form'</span><span style="color: #f8f8f2;">,function(){</span>
<span style="color: #66d9ef;">return</span> <span style="color: #f8f8f2;">View::make(</span><span style="color: #e6db74;">'verify_form'</span><span style="color: #f8f8f2;">);</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
verify_form file<br />
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f8f8f2;">Name:</span> <span style="color: #f8f8f2;">{{</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">_POST[</span><span style="color: #e6db74;">'uname'</span><span style="color: #f8f8f2;">]}}</span><span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">></span>
<span style="color: #f8f8f2;">Password:</span> <span style="color: #f8f8f2;">{{</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">_POST[</span><span style="color: #e6db74;">'pass'</span><span style="color: #f8f8f2;">]}}</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
Remember the first route remains same in both the cases..and so the output.</div>
Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.com2tag:blogger.com,1999:blog-5065757883907128416.post-5706363997383514612015-04-10T10:40:00.001+05:302015-04-10T10:40:02.585+05:30Condition and loops in laravel<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
This post is about constructing loops and conditions in laravel using Blade template.So lets get started.<br />
Open the routes.php file and create an array.What we will do here is create an array an add some conditions and loops to it so that use of each conditions becomes more clear.We will be passing the array from routes.php to views if you don't know how to do this I suggest you to read <a href="http://learn-laravel.blogspot.in/2015/03/routing-in-laravel-with-route-parameters.html" target="_blank">Routing in Laravel with Route Parameters</a> . So lets get started<br />
Open routes.php and type in the following code<br />
<br />
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3
4</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f8f8f2;">Route::get(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f8f8f2;">,function(){</span>
<span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruitlist</span> <span style="color: #f92672;">=</span> <span style="color: #f8f8f2;">array(</span><span style="color: #e6db74;">'Apple'</span><span style="color: #f8f8f2;">,</span><span style="color: #e6db74;">'Mango'</span><span style="color: #f8f8f2;">,</span><span style="color: #e6db74;">'Banana'</span><span style="color: #f8f8f2;">);</span>
<span style="color: #66d9ef;">return</span> <span style="color: #f8f8f2;">View::make(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f8f8f2;">)</span><span style="color: #f92672;">-></span><span style="color: #f8f8f2;">withFruits(</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruitlist);</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
What we have done is just created an array of fruits and a route to fruit.blade.php using Laravel Magic method.Now we can access the fruits array in the fruit view.<br />
fruits.blade.php file<br />
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f92672;"><</span><span style="background-color: #1e0010; color: #960050;">!</span><span style="color: #f8f8f2;">DOCTYPE</span> <span style="color: #f8f8f2;">html</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">html</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">head</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">title</span><span style="color: #f92672;">></span><span style="color: #f8f8f2;">Fruits</span> <span style="color: #f8f8f2;">page</span><span style="color: #f92672;"></</span><span style="color: #f8f8f2;">title</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">head</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">body</span><span style="color: #f92672;">></span>
<span style="color: #f8f8f2;">{{</span> <span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruits[</span><span style="color: #ae81ff;">0</span><span style="color: #f8f8f2;">]</span> <span style="color: #f8f8f2;">}}</span> <span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #f8f8f2;">{{</span> <span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruits[</span><span style="color: #ae81ff;">1</span><span style="color: #f8f8f2;">]</span> <span style="color: #f8f8f2;">}}</span> <span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #f8f8f2;">{{</span> <span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruits[</span><span style="color: #ae81ff;">2</span><span style="color: #f8f8f2;">]</span> <span style="color: #f8f8f2;">}}</span> <span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #f8f8f2;">Using</span> <span style="color: #f8f8f2;">condition</span> <span style="color: #f8f8f2;">statement</span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #a6e22e;">@if</span><span style="color: #f8f8f2;">(count(</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruits)</span><span style="color: #f92672;">></span><span style="color: #ae81ff;">0</span><span style="color: #f8f8f2;">)</span>
<span style="color: #f8f8f2;">Fruits</span> <span style="color: #f8f8f2;">array</span> <span style="color: #f92672;">is</span> <span style="color: #f92672;">not</span> <span style="color: #f8f8f2;">empty</span> <span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #a6e22e;">@endif</span>
<span style="color: #a6e22e;">@if</span><span style="color: #f8f8f2;">(count(</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruits)</span><span style="color: #f92672;">></span><span style="color: #ae81ff;">3</span><span style="color: #f8f8f2;">)</span>
<span style="color: #f8f8f2;">Fruits</span> <span style="color: #f8f8f2;">array</span> <span style="color: #f8f8f2;">have</span> <span style="color: #f8f8f2;">more</span> <span style="color: #f8f8f2;">than</span> <span style="color: #ae81ff;">3</span> <span style="color: #f8f8f2;">fruits</span> <span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #a6e22e;">@elseif</span><span style="color: #f8f8f2;">(count(</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruits)</span><span style="color: #f92672;"><=</span><span style="color: #ae81ff;">3</span><span style="color: #f8f8f2;">)</span>
<span style="color: #f8f8f2;">Fruits</span> <span style="color: #f8f8f2;">array</span> <span style="color: #f8f8f2;">may</span> <span style="color: #f8f8f2;">have</span> <span style="color: #ae81ff;">3</span> <span style="color: #f8f8f2;">fruits</span> <span style="color: #f92672;">or</span> <span style="color: #f8f8f2;">less</span> <span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #a6e22e;">@endif</span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #f8f8f2;">Using</span> <span style="color: #66d9ef;">for</span> <span style="color: #f8f8f2;">loop</span> <span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #a6e22e;">@for</span><span style="color: #f8f8f2;">(</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">i</span> <span style="color: #f92672;">=</span> <span style="color: #ae81ff;">0</span> <span style="color: #f8f8f2;">;</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">i</span> <span style="color: #f92672;"><</span> <span style="color: #f8f8f2;">count(</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruits);</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">i</span><span style="color: #f92672;">++</span> <span style="color: #f8f8f2;">)</span>
<span style="color: #f8f8f2;">{{</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruits[</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">i]}}</span> <span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #a6e22e;">@endfor</span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #f8f8f2;">Using</span> <span style="color: #f8f8f2;">foreach</span> <span style="color: #f8f8f2;">loop</span><span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #a6e22e;">@foreach</span><span style="color: #f8f8f2;">(</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruits</span> <span style="color: #66d9ef;">as</span> <span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruit)</span>
<span style="color: #f8f8f2;">Fruit</span> <span style="color: #f92672;">is</span> <span style="color: #f8f8f2;">{{</span><span style="background-color: #1e0010; color: #960050;">$</span><span style="color: #f8f8f2;">fruit}}</span><span style="color: #f92672;"><</span><span style="color: #f8f8f2;">br</span><span style="color: #f92672;">/></span>
<span style="color: #a6e22e;">@endforeach</span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">body</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #f8f8f2;">html</span><span style="color: #f92672;">></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
We have demonstrated a few of basic conditions and loops in this example the rest can be coded in the same manner.All conditions and loops that are valid in PHP are valid in laravel,You can make use of any of those as per your requirement.<br />
The output<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0Sll2VYvhkWibMnGOEqgcSs7GGU9RHan2i8YI1PXfwHiUfSAzbiUC57tG-NTXFn6Wx9HMbq_o2Eb0OJ_YPE6PGy31W-zo_fEHk_A-OwJi7b6B3whLmRxo3uOXEza7i-BEx2sNzLogmZA/s1600/learn-laravel.blogspot.in+laravel+tutorials+2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0Sll2VYvhkWibMnGOEqgcSs7GGU9RHan2i8YI1PXfwHiUfSAzbiUC57tG-NTXFn6Wx9HMbq_o2Eb0OJ_YPE6PGy31W-zo_fEHk_A-OwJi7b6B3whLmRxo3uOXEza7i-BEx2sNzLogmZA/s1600/learn-laravel.blogspot.in+laravel+tutorials+2.jpg" height="400" width="291" /></a></div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.com1tag:blogger.com,1999:blog-5065757883907128416.post-25045287070892444542015-03-31T14:56:00.000+05:302015-03-31T14:58:50.345+05:30Passing data to views in laravel<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
In this post I will show you how to pass data to views in laravel.This post is going to be a bridge between the <a href="http://learn-laravel.blogspot.in/2015/03/basics-of-routing-in-laravel.html" target="_blank">route post</a> and <a href="http://learn-laravel.blogspot.in/2015/03/basics-of-blade-and-views-in-laravel-part1.html" target="_blank">views</a>.We will see how to pass data from routes.php file to views.<br />
To get started lets open up the text editor and open routes.php and fruits.blade.php file( We created this file in the last post)<br />
We will make some modifications in routes.php so that it is able to pass data to views/fruits.blade.php<br />
There are two ways for passing data to views from routes<br />
First one is like this<br />
<br />
<br />
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3
4</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #a6e22e;">Route</span><span style="color: #f92672;">::</span><span style="color: #66d9ef;">get</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f92672;">,</span><span style="color: #66d9ef;">function</span><span style="color: #f8f8f2;">(){</span>
<span style="color: #a6e22e;">$fruitname</span> <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"Apple"</span><span style="color: #f92672;">;</span>
<span style="color: #66d9ef;">return</span> <span style="color: #a6e22e;">View</span><span style="color: #f92672;">::</span><span style="color: #a6e22e;">make</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f8f8f2;">)</span><span style="color: #f92672;">-></span><span style="color: #66d9ef;">with</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'var'</span><span style="color: #f92672;">,</span><span style="color: #a6e22e;">$fruitname</span><span style="color: #f8f8f2;">);</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
here we made use of with method to pass the variable.with() method takes 2 arguments,First one is the string and the second one is the variable.The string defines how you want your variable to be called in the view.In our example we have called it as var.Thus we can access the var value in views<br />
Save the routes.php file.Open the fruits.blade.php and type in the following script<br />
fruits.blade.php<br />
<br />
<br />
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3
4
5
6
7
8
9</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f92672;"><!</span><span style="color: #a6e22e;">DOCTYPE</span> <span style="color: #a6e22e;">html</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #a6e22e;">html</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #a6e22e;">head</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #a6e22e;">title</span><span style="color: #f92672;">></span><span style="color: #a6e22e;">Fruits</span> <span style="color: #a6e22e;">page</span><span style="color: #f92672;"></</span><span style="color: #a6e22e;">title</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #a6e22e;">head</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #a6e22e;">body</span><span style="color: #f92672;">></span>
<span style="color: #f8f8f2;">{{</span> <span style="color: #a6e22e;">$var</span> <span style="color: #f8f8f2;">}}</span>
<span style="color: #f92672;"></</span><span style="color: #a6e22e;">body</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #a6e22e;">html</span><span style="color: #f92672;">></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
Save the file and open you browser and browse to localhost/laravel/public/fruits you should get the following output.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_ArWiHTDZwIeO0e0PVfxs_2uky-vaNGpR8RGtw9j_2YT5gzsRhTkLy-02rbIptkZre_Qfueh5sZtdAhdXde3U6CGQSZVAGgjXyPHOu169xJI9y5a3iBHKqy34VPL3ncFDifQWcnYFflY/s1600/learn-laravel.blogspot.in+laravel+tutorials+1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_ArWiHTDZwIeO0e0PVfxs_2uky-vaNGpR8RGtw9j_2YT5gzsRhTkLy-02rbIptkZre_Qfueh5sZtdAhdXde3U6CGQSZVAGgjXyPHOu169xJI9y5a3iBHKqy34VPL3ncFDifQWcnYFflY/s1600/learn-laravel.blogspot.in+laravel+tutorials+1.jpg" height="291" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Second way of passing the data</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
In this method we can pass the variable as an array without using the with() method.We can pass value as an array using key value pair.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3
4</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #a6e22e;">Route</span><span style="color: #f92672;">::</span><span style="color: #66d9ef;">get</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f92672;">,</span><span style="color: #66d9ef;">function</span><span style="color: #f8f8f2;">(){</span>
<span style="color: #a6e22e;">$fruitname</span> <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"Apple"</span><span style="color: #f92672;">;</span>
<span style="color: #66d9ef;">return</span> <span style="color: #a6e22e;">View</span><span style="color: #f92672;">::</span><span style="color: #a6e22e;">make</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f92672;">,</span> <span style="color: #a6e22e;">array</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'var'</span> <span style="color: #f92672;">=></span> <span style="color: #a6e22e;">$fruitname</span><span style="color: #f8f8f2;">));</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
The fruits.blade.php page remains the same and the out put too.
<br />
<br />
We can also pass multiple values using array method by adding key value pairs like<br />
<br />
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3
4</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #a6e22e;">Route</span><span style="color: #f92672;">::</span><span style="color: #66d9ef;">get</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f92672;">,</span><span style="color: #66d9ef;">function</span><span style="color: #f8f8f2;">(){</span>
<span style="color: #a6e22e;">$fruitname</span> <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"Apple"</span><span style="color: #f92672;">;</span>
<span style="color: #66d9ef;">return</span> <span style="color: #a6e22e;">View</span><span style="color: #f92672;">::</span><span style="color: #a6e22e;">make</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f92672;">,</span> <span style="color: #a6e22e;">array</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'var'</span> <span style="color: #f92672;">=></span> <span style="color: #a6e22e;">$fruitname</span><span style="color: #f92672;">,</span><span style="color: #e6db74;">'var2'</span><span style="color: #f92672;">=></span><span style="color: #a6e22e;">$somevariable</span><span style="color: #f92672;">,</span><span style="color: #e6db74;">'var3'</span><span style="color: #f92672;">=></span><span style="color: #a6e22e;">$someothervariable</span><span style="color: #f8f8f2;">);</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
</div>
<br />
<br />
And access the value of variable in the view using key.
<br />
with() method can also be used to send multiple values<br />
<br />
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3
4</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #a6e22e;">Route</span><span style="color: #f92672;">::</span><span style="color: #66d9ef;">get</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f92672;">,</span><span style="color: #66d9ef;">function</span><span style="color: #f8f8f2;">(){</span>
<span style="color: #a6e22e;">$fruitname</span> <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"Apple"</span><span style="color: #f92672;">;</span>
<span style="color: #66d9ef;">return</span> <span style="color: #a6e22e;">View</span><span style="color: #f92672;">::</span><span style="color: #a6e22e;">make</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f8f8f2;">)</span><span style="color: #f92672;">-></span><span style="color: #66d9ef;">with</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'var'</span><span style="color: #f92672;">,</span><span style="color: #a6e22e;">$fruitname</span><span style="color: #f8f8f2;">)</span><span style="color: #f92672;">-></span><span style="color: #66d9ef;">with</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'var1'</span><span style="color: #f92672;">,</span><span style="color: #a6e22e;">$somevariable</span><span style="color: #f8f8f2;">)</span><span style="color: #f92672;">-></span><span style="color: #66d9ef;">with</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'var2'</span><span style="color: #f92672;">,</span><span style="color: #a6e22e;">$someothervariable</span><span style="color: #f8f8f2;">)</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
Accessed in the same way in views.<br />
Next post will be about sending data using magic methods.</div>
Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.com2tag:blogger.com,1999:blog-5065757883907128416.post-37623664259325196382015-03-28T15:22:00.000+05:302015-03-28T15:22:01.735+05:30Basics of blade and views in laravel (Part-1)<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
In the last post we learned how to <a href="http://learn-laravel.blogspot.in/2015/03/routing-in-laravel-with-route-parameters.html" target="_blank">create routes in laravel with route parameters</a> but in that tutorial we did not create any view we only returned plain text.In this post I will show you how to create a view for a particular route using blade template engine.Since Laravel is a framework based on MVC architecture we have to follow certain standard format while developing our Laravel Applications<br />
Before we jump on to code lets understand what is a view?<br />
Views typically contain the HTML of your application and provide a convenient way of separating your controller and domain logic from your presentation logic. Views are stored in the resources/views folder<br />
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPlAALYco2zGNKwgDvCxwmJZKP-JRtGOYDlBBvNZdOzR__bIu1Ha2U-HBdkpbbx32b3QX-VQLAoLHFIPNrCwPANJ2hGDDOnUSX5a04dJgQKyn08iRmn0YefEGAQYA2rbs9WPU2PAkuvTo/s1600/learn-laravel.blogspot.in+laravel+tutorials+1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPlAALYco2zGNKwgDvCxwmJZKP-JRtGOYDlBBvNZdOzR__bIu1Ha2U-HBdkpbbx32b3QX-VQLAoLHFIPNrCwPANJ2hGDDOnUSX5a04dJgQKyn08iRmn0YefEGAQYA2rbs9WPU2PAkuvTo/s1600/learn-laravel.blogspot.in+laravel+tutorials+1.jpg" height="400" width="283" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div>
Now lets jump into the code</div>
<div>
Open routes.php located in app/Http folder and create a new route.Read more about <a href="http://learn-laravel.blogspot.in/2015/03/basics-of-routing-in-laravel.html" target="_blank">creating routes</a>.</div>
<div>
<br /></div>
<div>
</div>
<div>
<br />
<br /></div>
</div>
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #a6e22e;">Route</span><span style="color: #f92672;">::</span><span style="color: #66d9ef;">get</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f92672;">,</span><span style="color: #66d9ef;">function</span><span style="color: #f8f8f2;">(){</span>
<span style="color: #66d9ef;">return</span> <span style="color: #a6e22e;">View</span><span style="color: #f92672;">::</span><span style="color: #a6e22e;">make</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'fruits'</span><span style="color: #f8f8f2;">);</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
<br />
Save the file.Create a new file named fruits.blade.php in the views folder and dump in some basic php stuff and save the file.I just did this<br />
<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;"> 1
2
3
4
5
6
7
8
9
10</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #f92672;"><!</span><span style="color: #a6e22e;">DOCTYPE</span> <span style="color: #a6e22e;">html</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #a6e22e;">html</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #a6e22e;">head</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #a6e22e;">title</span><span style="color: #f92672;">></span><span style="color: #a6e22e;">Fruits</span> <span style="color: #a6e22e;">page</span><span style="color: #f92672;"></</span><span style="color: #a6e22e;">title</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #a6e22e;">head</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><</span><span style="color: #a6e22e;">body</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"><?</span><span style="color: #a6e22e;">php</span> <span style="color: #a6e22e;">$var</span> <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"Fruits view"</span><span style="color: #f92672;">;</span> <span style="color: #f92672;">?></span>
<span style="color: #f8f8f2;">{{</span> <span style="color: #a6e22e;">$var</span> <span style="color: #f8f8f2;">}}</span>
<span style="color: #f92672;"></</span><span style="color: #a6e22e;">body</span><span style="color: #f92672;">></span>
<span style="color: #f92672;"></</span><span style="color: #a6e22e;">html</span><span style="color: #f92672;">></span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
Open the browser and navigate to localhost/laravel/public/fruits(According to my file structure yours might vary).You should get the following output.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg3j0IzpQ2Ey7doUW7sZguIpw3jja6044YuqdIINWQBf-YgkL7kxcjDufxWq4tBcMhKPSHxmQf0bkcjLHsEva5B42MgesuelUI-TyOKCsl9ZRbmXmrLKJjRqg0THRMfTj9zjQgrGqahEo/s1600/learn-laravel.blogspot.in+laravel+tutorials+2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg3j0IzpQ2Ey7doUW7sZguIpw3jja6044YuqdIINWQBf-YgkL7kxcjDufxWq4tBcMhKPSHxmQf0bkcjLHsEva5B42MgesuelUI-TyOKCsl9ZRbmXmrLKJjRqg0THRMfTj9zjQgrGqahEo/s1600/learn-laravel.blogspot.in+laravel+tutorials+2.jpg" height="268" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
What we just did is created a route to fruit view.The function in the route called the static make method of the view class and the argument that it takes is a view.Make sure that a view exists before you create a route otherwise you will be presented with a page full of errors.We named the view as fruit.blade.php we used the blade extension to tell the framework that we are using blade templating engine.You might have noticed that<b> {{ $var }} </b>did the job of <b>echo $var</b>.This is where blade template becomes handy,it makes code clean and tidy and removes the need of those untidy <? echo ?> when you want to print something.Blade template is not limited to only printing on page but it has many uses which we will see in the later posts.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.com0tag:blogger.com,1999:blog-5065757883907128416.post-29679806166050217042015-03-27T20:47:00.000+05:302015-03-27T20:47:00.460+05:30Routing in laravel with route parameters<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
This post is about routing in laravel with route parameters in the previous post we saw the basics of routing without route parameters.If you are new to routing in laravel then you should have a look at my previous post about <a href="http://learn-laravel.blogspot.in/2015/03/basics-of-routing-in-laravel.html" target="_blank">basics of routing in laravel</a>.So let's start<br />
<div>
Why to use route parameters?</div>
<div>
Many a times a we create a route which are similar,E.g if you have a blogging website your URL will look something like this learn-laravel.blogspot.in/articles/article-name.So if you have 50 articles in your website creating 50 routes in routes.php is not a good idea.If we observe the URL carefully</div>
<div>
learn-laravel.blogspot.in/articles/ will remain same for all requested articles only the article name will differ from article to article.So by using route parameters we can group together similar looking paramters.Let's jump into pratical example.</div>
<div>
Open routes.php file located in app/Http with your favorite text editor.</div>
<div>
You will find some stuff already present in that file,those routes deals with routing the default hopepage of laravel framework.We have nothing to do with those routes since we are creating our new route.</div>
<div>
Type the following line in routes.php file</div>
<div>
<br /></div>
<div>
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #a6e22e;">Route</span><span style="color: #f92672;">::</span><span style="color: #66d9ef;">get</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'articles/{article_name}'</span><span style="color: #f92672;">,</span><span style="color: #66d9ef;">function</span><span style="color: #f8f8f2;">(){</span>
<span style="color: #66d9ef;">return</span> <span style="color: #e6db74;">'Inside article_name was requested'</span><span style="color: #f92672;">;</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
save the file open your browser and browse to <i>localhost/laravel/public/articles/hello</i> (According to my file structure).You will get something like this<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjRv1glpweSushMVtvEVASOlmLtelsnSXYefIrNBfksrvETAoBVRIdVFDhq2TqECUpjjQ7GkLOe452YqJwfqp3Dl7weztYp-dL22fznUCrmxPkUVWgDM1iqkelS17BH1Wbt-AZCFEWQgA/s1600/learn-laravel.blogspot.in+laravel+tutorials+1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjRv1glpweSushMVtvEVASOlmLtelsnSXYefIrNBfksrvETAoBVRIdVFDhq2TqECUpjjQ7GkLOe452YqJwfqp3Dl7weztYp-dL22fznUCrmxPkUVWgDM1iqkelS17BH1Wbt-AZCFEWQgA/s1600/learn-laravel.blogspot.in+laravel+tutorials+1.jpg" height="178" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Here hello becomes the article name.You can try anything e.g <i>localhost/laravel/public/articles/blah-blah</i>.This will still work but if you browse to localhost/laravel/public/articles</div>
you will be presented with a whole page of error.So how to make this route common so that this works both for <i>localhost/laravel/public/articles/hello</i> and<i> localhost/laravel/public/articles</i> without error.<br />
<div class="" style="clear: both; text-align: left;">
Go back to routes.php file</div>
<br /></div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #272822; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3
4
5
6</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #a6e22e;">oute</span><span style="color: #f92672;">::</span><span style="color: #66d9ef;">get</span><span style="color: #f8f8f2;">(</span><span style="color: #e6db74;">'articles/{article_name?}'</span><span style="color: #f92672;">,</span><span style="color: #66d9ef;">function</span><span style="color: #f8f8f2;">(</span><span style="color: #a6e22e;">$article_name</span><span style="color: #f92672;">=</span><span style="color: #66d9ef;">null</span><span style="color: #f8f8f2;">){</span>
<span style="color: #66d9ef;">if</span> <span style="color: #f8f8f2;">(</span><span style="color: #a6e22e;">$article_name</span><span style="color: #f92672;">==</span><span style="color: #66d9ef;">null</span><span style="color: #f8f8f2;">)</span> <span style="color: #f8f8f2;">{</span>
<span style="color: #66d9ef;">return</span> <span style="color: #e6db74;">'No specific article was requested'</span><span style="color: #f92672;">;</span>
<span style="color: #f8f8f2;">}</span>
<span style="color: #66d9ef;">return</span> <span style="color: #a6e22e;">$article_name</span> <span style="color: #f8f8f2;">.</span><span style="color: #e6db74;">' article was requested'</span><span style="color: #f92672;">;</span>
<span style="color: #f8f8f2;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
Open your browser navigate to <i>localhost/laravel/public/articles/hello</i> you will get the article name in the output (hello in this case)<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHQuVSYkdbOiqamwArsH7UDkdHFh5Z1KZ5Sm68yxWzwRpROC865KY8Ljc2c0wC7i6ogt7f_7Eq3PYuQgK_5WT4DjBcvgQ-YpMePckRkCshFk5c0rgIRIt7g90P8reyIy_KtKuUctSwWxM/s1600/learn-laravel.blogspot.in+laravel+tutorials+2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHQuVSYkdbOiqamwArsH7UDkdHFh5Z1KZ5Sm68yxWzwRpROC865KY8Ljc2c0wC7i6ogt7f_7Eq3PYuQgK_5WT4DjBcvgQ-YpMePckRkCshFk5c0rgIRIt7g90P8reyIy_KtKuUctSwWxM/s1600/learn-laravel.blogspot.in+laravel+tutorials+2.jpg" height="175" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="" style="clear: both; text-align: left;">
navigate to<i> localhost/laravel/public/articles</i></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD_yq-j3oeG85grII2ZFu4UEpyQmUUbEzTW_EzUuI3ATC0ms4Yzh0f_MOSfsjAEYhMJyAiisZcQc8_dXe7lSuK573Ik8LlNlGtT8YtAoS6hSO-HSJ3-nAiknMyV2FSSeNmN6povcHne7w/s1600/learn-laravel.blogspot.in+laravel+tutorials+3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD_yq-j3oeG85grII2ZFu4UEpyQmUUbEzTW_EzUuI3ATC0ms4Yzh0f_MOSfsjAEYhMJyAiisZcQc8_dXe7lSuK573Ik8LlNlGtT8YtAoS6hSO-HSJ3-nAiknMyV2FSSeNmN6povcHne7w/s1600/learn-laravel.blogspot.in+laravel+tutorials+3.jpg" height="176" width="320" /></a></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: left;">
So this route work in both the cases.</div>
<div style="text-align: left;">
What we did is we made the <b><u>{article_name}</u></b> parameter optional by adding <b>?</b> (<b>{article_name}?</b>) and passed the parameter in the anonymous function <b>function($article_name=<u>null</u>)</b>.Since the parameter is optional it is necessary to assign null value.Then we did a basic check whether $article_name is null or !null and produced the result according.</div>
<div style="text-align: left;">
You can use as many optional parameters in the route but make sure to assign null value.So this was all about routing in laravel with route parameters.</div>
<div style="text-align: left;">
<br /></div>
<br />
<br /></div>
Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.com3tag:blogger.com,1999:blog-5065757883907128416.post-23034158718861212022015-03-26T16:17:00.001+05:302015-03-26T16:17:27.842+05:30Basics of routing in laravel<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
<br /></div>
<div dir="ltr" style="text-align: left;" trbidi="on">
This tutorial is about the basic routing in laravel.Before we move on to routing code let's first understand what is router and routing in laravel web application?<br />
Router is a component of a web application which is responsible for producing correct response for a particular requested URL.Routing is the process of taking the requested URL and deciding which application handler will handle the current request.<br />
So whenever to type a URL in the browser the Routers setup at the servers examine the URL and decide how to handle it.<br />
In similar manner laravel framework too has routing mechanism setup inside the framework.The file which handles all the routes requested is called routes.php which is located in app/Http folder and open the routes.php file.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiju79yQlxmUQ2aujSQdlJft2J_A15DuNqsHnkW2ge3cKihzHko3zbA5bOsNv_G7x1QvWMjRWemwIhieeL_9B6aoBSZ6fpBBti1NAwY7AyJuObhbFAa99bifbWtie05ZQgKymZPEJEnM1M/s1600/learn-laravel.blogspot.in+laravel+tutorials.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiju79yQlxmUQ2aujSQdlJft2J_A15DuNqsHnkW2ge3cKihzHko3zbA5bOsNv_G7x1QvWMjRWemwIhieeL_9B6aoBSZ6fpBBti1NAwY7AyJuObhbFAa99bifbWtie05ZQgKymZPEJEnM1M/s1600/learn-laravel.blogspot.in+laravel+tutorials.jpg" height="302" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
As you see there are various routes defined in this file.Routes are defined for base url(/) and home<br />
Go to browser and type localhost/laravel/public (According to my file structure).You will se something like this<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdQ8ZrYCQwmuqtvIY-jQ1KFGZbTqrC7YonyiM7KuE-XhD8Xa0k86jzPBcBQKrISaYUH5mwvk4aRKsgrlx1IsryQTl_oDue8iagiI1-72sBt5fiNfwYeduI4nGKCf6MJklSvJpK3w9bIV0/s1600/learn-laravel.blogspot.in+laravel+tutorials+1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdQ8ZrYCQwmuqtvIY-jQ1KFGZbTqrC7YonyiM7KuE-XhD8Xa0k86jzPBcBQKrISaYUH5mwvk4aRKsgrlx1IsryQTl_oDue8iagiI1-72sBt5fiNfwYeduI4nGKCf6MJklSvJpK3w9bIV0/s1600/learn-laravel.blogspot.in+laravel+tutorials+1.jpg" height="205" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
If you type localhost/laravel/public/home (According to my file structure).You will se something like this<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpYZvch8L5EGNaPzn-PqJ71Bjj4DRbcFgfdW8_YbrA3lDh6MApLp_qtoRidHzrP1DiMw7sFSgjKGTYtqeshVOGz1MYh1HAkm5M5-r-yNkes9Vo7nx1CtsJnxKL-0erN8ULC2-aTEJXWxU/s1600/learn-laravel.blogspot.in+laravel+tutorials+2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpYZvch8L5EGNaPzn-PqJ71Bjj4DRbcFgfdW8_YbrA3lDh6MApLp_qtoRidHzrP1DiMw7sFSgjKGTYtqeshVOGz1MYh1HAkm5M5-r-yNkes9Vo7nx1CtsJnxKL-0erN8ULC2-aTEJXWxU/s1600/learn-laravel.blogspot.in+laravel+tutorials+2.jpg" height="205" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br /></div>
<!-- Syntax high -->
<br />
<pre style="background: #000; color: white; padding: 10px;">Route<span style="color: #cc7833;">:</span><span style="color: #cc7833;">:</span><span style="color: #c83730;">get</span>(<span style="color: #66cc33;">'/'</span>, <span style="color: #66cc33;">'WelcomeController@index'</span>);
Route<span style="color: #cc7833;">:</span><span style="color: #cc7833;">:</span><span style="color: #c83730;">get</span>(<span style="color: #66cc33;">'home'</span>, <span style="color: #66cc33;">'HomeController@index'</span>);
</pre>
<br />
These two lines are responsible for displaying correct pages when base URL and home is requested.<br />
What does these lines means?<br />
This means we are calling the static get method of Route class this get method takes two arguments.The first argument is requested route and second parameter is the handler.You can see the '<b>WelcomeController@index</b>' and <b>'HomeControlller@index</b>' in the app/Controllers folder<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1m2WZUPw3r2X2VJhbXsZM2jj_4QpZKuRTmB3VMP45q_HGnVTrmOF5CU2cEjt7vthFdrHnjHHGtOYmRWmE9g8FgUysPjZuH_-kbomiAvpw7F3I8lY43CQ9RadzLEbe08djMcHkKxag18w/s1600/learn-laravel.blogspot.in+laravel+tutorials+3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1m2WZUPw3r2X2VJhbXsZM2jj_4QpZKuRTmB3VMP45q_HGnVTrmOF5CU2cEjt7vthFdrHnjHHGtOYmRWmE9g8FgUysPjZuH_-kbomiAvpw7F3I8lY43CQ9RadzLEbe08djMcHkKxag18w/s1600/learn-laravel.blogspot.in+laravel+tutorials+3.jpg" height="297" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
How to create our own route in laravel?</div>
<div class="separator" style="clear: both; text-align: left;">
Lets create a route for fruit page</div>
<div class="separator" style="clear: both; text-align: left;">
Open routes.php and add the following lines </div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</div>
<!-- HTML generated using hilite.me --><br />
<div style="background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #cccccc;">Route::get('fruit',function(){</span>
<span style="color: #cccccc;"> return 'Welcome to the fruit page';</span>
<span style="color: #cccccc;">});</span>
</pre>
</td></tr>
</tbody></table>
</div>
<br />
Save the file and navigate to localhost/laravel/public/fruit (According to my file structure).You will see something like this
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSsY7jRGDMAJ6mLgh_ooxGgi5-uFuRG46Bxhmfo77yna6noy-OWDRSXD1TVRfDdhvnxGzZqwwaco-tOzoihjm_ROQsDH9m_LIrCkNoxnNSO24nReiVpaJ4GbPAEFhz3cw61-y5PExswkQ/s1600/learn-laravel.blogspot.in+laravel+tutorials+4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSsY7jRGDMAJ6mLgh_ooxGgi5-uFuRG46Bxhmfo77yna6noy-OWDRSXD1TVRfDdhvnxGzZqwwaco-tOzoihjm_ROQsDH9m_LIrCkNoxnNSO24nReiVpaJ4GbPAEFhz3cw61-y5PExswkQ/s1600/learn-laravel.blogspot.in+laravel+tutorials+4.jpg" height="182" width="400" /></a></div>
<br />
What this does is whenever fruit page is requested the anonymous function is called which returns plain text in this example.We will keep this simple in this post.We will deal with creating and routing to particular controller in later posts,So keep following.<br />
Similarly you can create a route for something like fruit/apple<br />
<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #000000; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;">
<table><tbody>
<tr><td><pre style="line-height: 125%; margin: 0;">1
2
3</pre>
</td><td><pre style="line-height: 125%; margin: 0;"><span style="color: #cccccc;">Route::get('fruit/apple',function(){</span>
<span style="color: #cccccc;"> return ' Welcome to fruit/apple page';</span>
<span style="color: #cccccc;">});</span>
</pre>
</td></tr>
</tbody></table>
<br /></div>
<br />
Save the file and navigate to localhost/laravel/public/fruit/apple (According to my file structure).You will see something like this<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWHILeQqbWSrYmhYrp2Os8wCizEsQtlwuIYu_4YT0CNRZgO5lD1wLnAL-A3xmebs6X3PE2s1Wj0wdHhaLn9G3Ax-ST_DeJ2xe-43WkC-Ocp0n7jW8sNYPWqahBJ8UanSskMfuOz6O2wnw/s1600/learn-laravel.blogspot.in+laravel+tutorials+5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWHILeQqbWSrYmhYrp2Os8wCizEsQtlwuIYu_4YT0CNRZgO5lD1wLnAL-A3xmebs6X3PE2s1Wj0wdHhaLn9G3Ax-ST_DeJ2xe-43WkC-Ocp0n7jW8sNYPWqahBJ8UanSskMfuOz6O2wnw/s1600/learn-laravel.blogspot.in+laravel+tutorials+5.jpg" height="175" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
If you try to route any page that has not been declared in the routes.php file you will get an error.</div>
<div class="separator" style="clear: both; text-align: left;">
Creating routes for each page is not handy in the coming post we will deal with how to create routes that can handle multiple requests based on parameters.</div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.com2tag:blogger.com,1999:blog-5065757883907128416.post-88111712525254070392015-03-24T12:15:00.000+05:302015-03-24T12:16:29.949+05:30How to install laravel framework<div dir="ltr" style="text-align: left;" trbidi="on">
This post is about installing Laravel framework on your computer provided that you have local server up and running.If you don't know how to install a local server on to your computer you can read my previous post on <a href="http://learn-laravel.blogspot.in/2015/03/installing-local-server-on-computer.html" target="_blank">How to install a local server on computer</a>.<br />
So lets get started.<br />
Open your favorite browser an search for Composer.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjqT4Gun0nR7QmHP4r7bG5B9dF0AAyeo7p85dmBrw0IdX3v4xMWLZcYsPdEFYdtC-mIaibI5F_J7o6xEEhOU6FUvQKriY5EeWLRPRuicqKeFJ7XjWDP4KgzX1YlkjcJ-WiBR6RN2d8mHI/s1600/1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjqT4Gun0nR7QmHP4r7bG5B9dF0AAyeo7p85dmBrw0IdX3v4xMWLZcYsPdEFYdtC-mIaibI5F_J7o6xEEhOU6FUvQKriY5EeWLRPRuicqKeFJ7XjWDP4KgzX1YlkjcJ-WiBR6RN2d8mHI/s1600/1.jpg" height="208" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
But before we download composer we need to allow open SSL.To do this go to your</div>
<div class="separator" style="clear: both; text-align: left;">
<i style="font-weight: bold;"><br /></i></div>
<div class="separator" style="clear: both; text-align: left;">
<i style="font-weight: bold;">wamp</i>-<i><b>folder/bin/php/php5.5.12(</b>number depends on your version<b>)/php.ini</b></i> </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Open the php.ini file with notepad and search for openssl and make sure that the line</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i>extension=php_openssl.dll</i></b></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
is uncommented</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEii77LgK0yr6W6JkfFcvbZKgmPC5Rj1dQSxK5H1xk3B-TcSrxRZEzCcIfBvaEfSoICq-JRhCtE9vAHe0S1WhyphenhyphenjnBf_vzT-GUb32zNV4__XOhsfClxqlbedLCZ3a1ardBnVE5CSSAMvhnog/s1600/4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEii77LgK0yr6W6JkfFcvbZKgmPC5Rj1dQSxK5H1xk3B-TcSrxRZEzCcIfBvaEfSoICq-JRhCtE9vAHe0S1WhyphenhyphenjnBf_vzT-GUb32zNV4__XOhsfClxqlbedLCZ3a1ardBnVE5CSSAMvhnog/s1600/4.jpg" height="160" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Go back to composer page in browser and hit the download buton</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjA7xzxOn1TrK98bRxd_ClvhNCfVV7_UHgEWcXZDxZw9WAftd7dxH5F2hUySpxVqaiFkWVjC8VBqgbJjOUeIRIUASDFiA-BqDzyrNffZwJoqkVuVcnuphbozelFQ4PlCxqQCkz13IVo3Ig/s1600/2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjA7xzxOn1TrK98bRxd_ClvhNCfVV7_UHgEWcXZDxZw9WAftd7dxH5F2hUySpxVqaiFkWVjC8VBqgbJjOUeIRIUASDFiA-BqDzyrNffZwJoqkVuVcnuphbozelFQ4PlCxqQCkz13IVo3Ig/s1600/2.jpg" height="302" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Copy the second link from the download page</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIaMbh7kzEh6pB9cNpOkwjb_ZOxswidEEGFzf4QyOfxRtIbZkTKC9qCSrvOS3Rt9PDCs4t-ZUUDx4oOjs6p59G7exWU7GVXMDzCodP3JB6VlzWLOi74Rc3fY46qOKs6t4WuSIILR_Tj-k/s1600/3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIaMbh7kzEh6pB9cNpOkwjb_ZOxswidEEGFzf4QyOfxRtIbZkTKC9qCSrvOS3Rt9PDCs4t-ZUUDx4oOjs6p59G7exWU7GVXMDzCodP3JB6VlzWLOi74Rc3fY46qOKs6t4WuSIILR_Tj-k/s1600/3.jpg" height="268" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Open Command prompt and browse to your Wamp folder and paste the link copied in the previous step</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnP2ImJ8fB3WQrHHGsZudObmjCYbqbw5aSYfvF0442RFHSAGmfFIRp91881BRG6u3kPZu1kfqyJYlg7rFvdJHf7NN-Mw4hn04mCm6QrUh8s7mvfmuZaAvaNG95A7DaLSa-azWAS7d9aXE/s1600/5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnP2ImJ8fB3WQrHHGsZudObmjCYbqbw5aSYfvF0442RFHSAGmfFIRp91881BRG6u3kPZu1kfqyJYlg7rFvdJHf7NN-Mw4hn04mCm6QrUh8s7mvfmuZaAvaNG95A7DaLSa-azWAS7d9aXE/s1600/5.jpg" height="82" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Now type</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b><i>php composer.phar create-project laravel/laravel www --prefer-dist</i></b> </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
into the CMD and hit enter this will install laravel framework into www folder.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Now we are done with the installation but before we start using the framework we need to set certain permissions to the framework.Go to </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Wamp-folder/www/</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Right click on app folder and open properties</div>
<div class="separator" style="clear: both; text-align: left;">
Click on the security Tab</div>
<div class="separator" style="clear: both; text-align: left;">
Select system and make sure that it has write permission</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjACSePnopBi4ISBY6HvWEOPqn1p8H8MMCDKtxJVZUVXHHheMuabTS_xyQqxd88EEPO6VcVk3xzdidl86KcJbZRfs2G54lpK2hPKILGahXbUYEit0dZTPLXRBalC4X-Dyjq64YzZ6__lQg/s1600/6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjACSePnopBi4ISBY6HvWEOPqn1p8H8MMCDKtxJVZUVXHHheMuabTS_xyQqxd88EEPO6VcVk3xzdidl86KcJbZRfs2G54lpK2hPKILGahXbUYEit0dZTPLXRBalC4X-Dyjq64YzZ6__lQg/s1600/6.jpg" height="400" width="306" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Now go to </div>
<div class="separator" style="clear: both; text-align: left;">
Wamp-folder/bin/apache/apache2.4.9/conf/</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Open the httpd.conf file with notepad and serach for mod_rewrite and remove the # which is in front of the line</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpvLfk_t5-wqXA9zvejNcjnfd4XtyjNz_lks_GEsijcLFUB6KUsVtAxU-S8xXw9hB-GaTKjqQG1ZYW4LkjuDypu_E3ptS6UUVOW60B4_WW1eCpAN1AYx9pkCaouFe-uu6exdRVXTSPx8w/s1600/7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpvLfk_t5-wqXA9zvejNcjnfd4XtyjNz_lks_GEsijcLFUB6KUsVtAxU-S8xXw9hB-GaTKjqQG1ZYW4LkjuDypu_E3ptS6UUVOW60B4_WW1eCpAN1AYx9pkCaouFe-uu6exdRVXTSPx8w/s1600/7.jpg" height="103" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Finally we come to the end of this long process.The only thing left now is to check if all the installation was successful</div>
<div class="separator" style="clear: both; text-align: left;">
Open up the browser type in localhost you should get a list of folder.</div>
<div class="separator" style="clear: both; text-align: left;">
Click on public folder you should get a page like this</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih2H2Y8oEd6JnN-jWYqLrUi5N8x-zpRwysCi8ip35_0ppNAx6JWRDkT5mAQGI0sJq3Ky8ouc1SpKvZJ2DeO1MkYTN1RxiiAm4j5iMsH-A21mebISI8CpI4iq8oIFmgZPzh6b9ANESfNLw/s1600/8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih2H2Y8oEd6JnN-jWYqLrUi5N8x-zpRwysCi8ip35_0ppNAx6JWRDkT5mAQGI0sJq3Ky8ouc1SpKvZJ2DeO1MkYTN1RxiiAm4j5iMsH-A21mebISI8CpI4iq8oIFmgZPzh6b9ANESfNLw/s1600/8.jpg" height="220" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Thats all you have successfully installed Laravel framework on your local server </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.com5tag:blogger.com,1999:blog-5065757883907128416.post-88240268369755732842015-03-23T19:58:00.000+05:302015-03-24T11:09:54.466+05:30Installing a Local Server<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
In this post I will show you how to install local server on your computer.Installing a local server depends on what operating system you are using.Windows users should install <a href="http://www.wampserver.com/en/">WAMP</a>,LINUX users LAMP and MAC users <a href="https://www.mamp.info/en/">MAMP</a><br />
<div>
The Installation process is pretty simple</div>
<div>
Download <a href="http://www.wampserver.com/en/">WAMP</a>/LAMP/<a href="https://www.mamp.info/en/">MAMP</a>.(Windows users make sure you have Visual Studio installed).</div>
<div>
<br />
Windows users follow these steps:-<br />
Click on the downloaded file<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivlRO_T50d7YGbLFlyQqku6CdY5ENqsdUhTmD_Kf-R0Eo6c25xGv2RBdLh2rSHJbyKBhXK1UomPCgyAyaY3kUuhQIYCfn41akBuSdzeyEg43zvUKvdw7Otpt4ZnEZFbR9ErJwj5qv4gMs/s1600/2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivlRO_T50d7YGbLFlyQqku6CdY5ENqsdUhTmD_Kf-R0Eo6c25xGv2RBdLh2rSHJbyKBhXK1UomPCgyAyaY3kUuhQIYCfn41akBuSdzeyEg43zvUKvdw7Otpt4ZnEZFbR9ErJwj5qv4gMs/s1600/2.jpg" height="307" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_qS1azGaCjGHVCVmC6kL3IYaxEZXzF0DmaNMVwCovzZupjg2kLzBkdOsShJvow6hcDtphtGODnAQvKi7n5Hitzj4f7YZ-iVaCIyILt2wiWv0TYDZoKhz8MtaNrKrcF9EwETivicyeWek/s1600/3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_qS1azGaCjGHVCVmC6kL3IYaxEZXzF0DmaNMVwCovzZupjg2kLzBkdOsShJvow6hcDtphtGODnAQvKi7n5Hitzj4f7YZ-iVaCIyILt2wiWv0TYDZoKhz8MtaNrKrcF9EwETivicyeWek/s1600/3.jpg" height="308" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWLfVtfYEUBNVu7r4Z-zLsKMShsU158WEMI44ksu07bzXH9c98GfsLC2k0E8ymxLFnjIXDwx_CSu1UW-3XI3CLVfCKV3dwBpoJFHGim-241aucdlFVLpmkfKXSja0OsapVQ3TWsEOmEOU/s1600/4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWLfVtfYEUBNVu7r4Z-zLsKMShsU158WEMI44ksu07bzXH9c98GfsLC2k0E8ymxLFnjIXDwx_CSu1UW-3XI3CLVfCKV3dwBpoJFHGim-241aucdlFVLpmkfKXSja0OsapVQ3TWsEOmEOU/s1600/4.jpg" height="310" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwBY-c3gg3AJcIPTlUKNQKeuyzziYLeBYyaNMIPDTLuqfPbj8u2WAkGjhqdaIJMBABlxhP4skZeYIYToxKTx0awntE8lXzUrhTozFKFpiPQ7C9IUZdgMR2FyopyYZ-2oLrpB4eRiaDDuk/s1600/5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwBY-c3gg3AJcIPTlUKNQKeuyzziYLeBYyaNMIPDTLuqfPbj8u2WAkGjhqdaIJMBABlxhP4skZeYIYToxKTx0awntE8lXzUrhTozFKFpiPQ7C9IUZdgMR2FyopyYZ-2oLrpB4eRiaDDuk/s1600/5.jpg" height="306" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLfE8CoREW7gDWSrn4C1Pt8ahsl_2IZlSRzYtYUV1jvceCW12J7aTk0PjL8v7fXOrXT-6HgTt34C_zBzdh6QSQ35OXjRiykLydC4Qxq1ZzyLVc2nP4zWGlFJSPMM7SqyLhA1ts91rDkvE/s1600/6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLfE8CoREW7gDWSrn4C1Pt8ahsl_2IZlSRzYtYUV1jvceCW12J7aTk0PjL8v7fXOrXT-6HgTt34C_zBzdh6QSQ35OXjRiykLydC4Qxq1ZzyLVc2nP4zWGlFJSPMM7SqyLhA1ts91rDkvE/s1600/6.jpg" height="305" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMiZXzcSr9eYaG-MIH_f881wCTano8dRwbmBn-mn4-XykiT6Puvb7_5QE6I-U4Uv6P6vP8BOSYLvXGbErWqMB_qpt60Xq019Yyg19ZbOjDsTBo8QUJiNLLQHZ59P-4jsnXaY05tMiCuAY/s1600/7.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMiZXzcSr9eYaG-MIH_f881wCTano8dRwbmBn-mn4-XykiT6Puvb7_5QE6I-U4Uv6P6vP8BOSYLvXGbErWqMB_qpt60Xq019Yyg19ZbOjDsTBo8QUJiNLLQHZ59P-4jsnXaY05tMiCuAY/s1600/7.jpg" height="311" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtWCkhRHU83ESxyfQ1QSBgfJCRu0DHXaSMC-bIXhOhddFaADnb-e49a8kSd633bF-MkNWs_oukLrQs0ETkcCSZe0b3PdDULU-fCJWILRs4CB6bhFJllpz_wI432gAJgy2jrHQZZpuvwj8/s1600/8.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtWCkhRHU83ESxyfQ1QSBgfJCRu0DHXaSMC-bIXhOhddFaADnb-e49a8kSd633bF-MkNWs_oukLrQs0ETkcCSZe0b3PdDULU-fCJWILRs4CB6bhFJllpz_wI432gAJgy2jrHQZZpuvwj8/s1600/8.jpg" height="317" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5GRrPYA3sgp2fFwx7hY18P0REhdUWCJaiXiij5zvG61-5v2QJxf-mOZfqUq0lrEzYiZYx3wD2tcaaEHaT2UQC5m87FUITHmh0V4cO6riyX-tFl597TdqgS8_C4u5kji1SmRbj6MSEkBQ/s1600/9.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5GRrPYA3sgp2fFwx7hY18P0REhdUWCJaiXiij5zvG61-5v2QJxf-mOZfqUq0lrEzYiZYx3wD2tcaaEHaT2UQC5m87FUITHmh0V4cO6riyX-tFl597TdqgS8_C4u5kji1SmRbj6MSEkBQ/s1600/9.jpg" height="298" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKxCrsK7jQQPSGaEgT608hEChJG8dPzxmGwUEzaectkZsoTs6hE2FXSxkIc2_AR8XYV6orfeXNSUMz7n9vw81L-ExueJWTyc0t2pIt-_BITH44aNilJ52El5qW8TNwJ6d74NkaaHF1S6k/s1600/10.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKxCrsK7jQQPSGaEgT608hEChJG8dPzxmGwUEzaectkZsoTs6hE2FXSxkIc2_AR8XYV6orfeXNSUMz7n9vw81L-ExueJWTyc0t2pIt-_BITH44aNilJ52El5qW8TNwJ6d74NkaaHF1S6k/s1600/10.jpg" height="312" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg25xLhTotpMbmRxGW2vSibbBr5kneSWJSUXeJmrqg6b9QgTd2HVwg4pUoR8kXHnl_lPIspz_YOahxq410jGqaLbmmoS1danJnIwRevk4XVvLe2QLcb2HesqwVcqnd-YTD3dgtBIVD0o8E/s1600/11.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg25xLhTotpMbmRxGW2vSibbBr5kneSWJSUXeJmrqg6b9QgTd2HVwg4pUoR8kXHnl_lPIspz_YOahxq410jGqaLbmmoS1danJnIwRevk4XVvLe2QLcb2HesqwVcqnd-YTD3dgtBIVD0o8E/s1600/11.jpg" height="307" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAC0HdrNwezuamhordJMSwttoOWrnj7UX_nYFMRCdzQIUwHoIEX5X5-zL3iKTlIxZOXd89Ua1mjAdTQ4-cxCEsgEG_5W1NzIoWzB5F0y52BdL6hrF9MRPhXRS78GCs0Y2RriRdzCC2js4/s1600/12.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAC0HdrNwezuamhordJMSwttoOWrnj7UX_nYFMRCdzQIUwHoIEX5X5-zL3iKTlIxZOXd89Ua1mjAdTQ4-cxCEsgEG_5W1NzIoWzB5F0y52BdL6hrF9MRPhXRS78GCs0Y2RriRdzCC2js4/s1600/12.jpg" height="302" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Open your favorite browser and type localhost as the url.You should get the following page which ensures your installation was successful </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjk01ExMssqi5ZaPEZxKpNKATX-xWdPcfWmsOEZl0tspsur-cN9D9j_-uxwiIs3p5LjAD22AY_5r3PBLy4NQOvofuyyk9Nq4gVAWlVewOt3wO7dP3mhbVW5zidPg0XZ-x-1yXX7PdqU58/s1600/13.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjk01ExMssqi5ZaPEZxKpNKATX-xWdPcfWmsOEZl0tspsur-cN9D9j_-uxwiIs3p5LjAD22AY_5r3PBLy4NQOvofuyyk9Nq4gVAWlVewOt3wO7dP3mhbVW5zidPg0XZ-x-1yXX7PdqU58/s1600/13.jpg" height="237" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
For Linux users:-</div>
<br />
<br />
There are only three major steps to take care of in order to get your LAMP server up and running. <br />
<br />
<b>Apache</b><br />
<br />
From within your terminal window issue the command:<br />
<br />
<i>sudo apt-get install apache2</i><br />
<br />
<br />
If, by chance, you are using a distribution that does not use Sudo, you will need su to the root user and issue the above command without the sudo command.<br />
<br />
Depending on your OS installation, the above command might need to pick up some dependencies. If so, okay those dependencies. At the end of the installation, Apache should automatically start. If it doesn't, issue the following command:<br />
<br />
sudo /etc/init.d/apache2 start<br />
<br />
You can now open up a browser and point it to the IP address (or domain) of the server to get the famous "It works!" page. You are ready to move on to PHP.<br />
<br />
<b>PHP</b><br />
<br />
For the purposes of this article, we will assume the "P" stands for "PHP." To begin the process of installing PHP, issue the following command:<br />
<br />
<br />
<i>sudo apt-get install php5 libapache2-mod-php5</i><br />
<br />
NOTE: Again, depending upon your OS installation, this might require some dependencies to be met. Allow apt-get to pick up those dependencies.<br />
<br />
When the installation is complete, restart Apache with the command:<br />
<br />
sudo /etc/init.d/apache2 restart<br />
<br />
Now, let's give PHP a little test to make sure it has installed. In your terminal window, create a new file called test.php.<br />
<br />
Save that file and place it in /var/www/. Now, open up your browser to the address http://ADDRESS_OF_SERVER/test.php. Where ADDRESS_OF_SERVER is the actual address of your server. You should see "Test PHP Page" in the browser. You are now ready to move on to MySQL.<br />
<br />
<b>MySQL</b><br />
<br />
MySQL is the database piece of the puzzle. This installation requires a few more steps than what you've just experienced. The first step is to install the server itself with the command:<br />
<br />
<i>sudo apt-get install mysql-server</i><br />
<br />
Again, depending upon your OS installation, there might be some dependencies to be installed. After the installation is complete you need to log into the MySQL prompt and give the administrative user a password. Do this by following these steps:<br />
Log into MySQL with the command mysql -u root -p.<br />
As no password has been configured, you will only need to hit enter when prompted for the password.<br />
Enter the command SET PASSWORD FOR 'root'@'localhost' = PASSWORD ('YOURPASSWORD');Where YOURPASSWORD is the password you want to use for the administrative user.<br />
Now quit the MySQL prompt by issuing the command quit and hitting enter.<br />
Start the MySQL server with the command sudo /etc/init.d/mysql start.<br />
<br />
That's it. Your LAMP server is now up and running. But what about this one-command method? Simple. From your terminal window, issue the command:<br />
<br />
sudo tasksel<br />
<br />
<br />
This command will open a curses-based tool (see Figure 1) which allows you to select numerous software options for installation. One of those selections is a LAMP server. All you need to do is mark LAMP server for installation (scroll down with your arrow keys and then hit the space bar to select). Once you have selected LAMP server, hit the Tab key on the "button" and hit the Enter key.<br />
<br />
<br />
<img src="http://www.linux.com/images/stories/tasksel.png" /><br />
<br />
Figure 1<br />
<br />
You will have to answer a single question when you get to the MySQL portion of the install (what you want to use for the admin password). That's it.</div>
<div>
Source-(<a href="https://www.linux.com/learn/tutorials/288158-easy-lamp-server-installation">https://www.linux.com/learn/tutorials/288158-easy-lamp-server-installation</a>).</div>
<div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br /></div>
</div>
</div>
Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.com0tag:blogger.com,1999:blog-5065757883907128416.post-74958797990557480572015-03-23T18:48:00.000+05:302015-03-24T11:11:16.026+05:30Introduction to Laravel<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: center;">
</h2>
<div>
<b>What is Laravel and why should I learn Laravel?</b></div>
<div>
Laravel is a framework for PHP programming language.</div>
<div>
Think of a framework as a ordered structure within a programming language giving you the standard solutions to a typical problems.Using a framework reduces the burden of doing same thing again and again and stops you from re-inventing the wheel again and again.</div>
<div>
Laravel framework makes easy handling of frequently used processes such as:-</div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiocWaavRfpijI66uEbX-bFD4zCH5IN2vvBjabgs5qTnro_MgtSE-Ovq8bPefCI8qchzjdTtcSMwP3emyhFRHVZwc9vPH_ZZemK2RgzXGNvDMQXrSfWV4cFtgcs_O-6ElxRhDunhhj81HY/s1600/images.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiocWaavRfpijI66uEbX-bFD4zCH5IN2vvBjabgs5qTnro_MgtSE-Ovq8bPefCI8qchzjdTtcSMwP3emyhFRHVZwc9vPH_ZZemK2RgzXGNvDMQXrSfWV4cFtgcs_O-6ElxRhDunhhj81HY/s1600/images.png" /></a></div>
<ul style="text-align: left;">
<li>User Registration</li>
<li>Authentication</li>
<li>Session Handling</li>
<li>Database Migration</li>
<li>Form Validation etc</li>
</ul>
</div>
<div>
Coming back to framework there are a lot of PHP framework that already exists and neither a single of them is bad,but it depends on your utility.Few frameworks are</div>
<div>
<ul style="text-align: left;">
<li>CakePHP</li>
<li>CodeIgnitor</li>
<li>ZendFramework etc</li>
</ul>
</div>
<div>
The best way to know which one is better for a particular type of application is by learning all of them.So that strength and weakness of each framework is discovered.</div>
<div>
<br /></div>
<div>
<b>Why Laravel?</b></div>
<div>
<ul style="text-align: left;">
<li>Easy to learn</li>
<li>Excellent Documentation</li>
<li>Active community and forum support</li>
</ul>
</div>
<div>
But I will definitely suggest you to learn all the framework and work like a PRO :) </div>
<div>
<br /></div>
<div>
<b>What do you need to start learning Laravel?</b></div>
<div>
Basic understanding of PHP language.</div>
<div>
<br /></div>
<div>
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/05131233736151189575noreply@blogger.com0