Understanding Laravel Basic Routing

Syntax:

Route::HTTP_Request_Method(“URI_Path_Name’, function (){

//code

})

 

Example 1:

Route::get(‘/’, function () {

return view(‘welcome’);

});

Explain:

  • ‘/’ this character refer to   http://localhost:8000
  • view(‘welcome’), this code mean that it take welcome.blade.php file from resources/views folder

 

Example 2:

Open file routes/web.php and add this code:

Route::get(“salam”, function(){

return “Assalamu’alaikum”;

});

Explain:

  • ‘salam’ this string  refer to http://localhost:8000/salam
  • return “Assalamu’alaikum”, this code mean that it will display “Assalamu’alaikum”

Result:

basic_routing_echo

Example 3:

Open file routes/web.php and add this code:

Route::get(“toko”, function(){

return view(‘toko_sepatu’);

});

Explain:

  • ‘toko’ this string  refer to http://localhost:8000/toko
  • view(“toko_sepatu”), this code mean that it take toko_sepatu.blade.php file from resources/views folder

Create View

Create new file toko_sepatu.blade.php inside resources/views folder and insert this HTML code:

<h3>Laravel Basic Routes</h3>
<P> Alhamdulillah saya sudah mengerti tentang dasar route dalam laravel</p>

Result:

basic_routing_view

 

Thanks for reading

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *