Using Controller in Laravel

Hello Friends
How are you? Hope you are fine in health. Let’s go to start the work with Laravel Controller. Its a funny work. Let’s go to start funny journey…

In MVC (Model-View-Controller) patter, controller is the heart of them. All of the logical code of your site will be place in controller section. You have to extends your controller based on your base controller. Let’s go…

In our laravel directory go to application/controllers/ and create a new file called users.php. Now wrtie the below code…

<?php

class User_Controller extends Base_Controller{

public function action_index(){

echo “This is Our Index Page”;

}

public function action_login(){

echo “This is our Login Page”;

}

}

?>

OK, we have completed the first controller coding of your life for laravel. Now we have to register into our routing file. So, lets go to /application/routes.php and write the code accroding the below-

Route::controller(‘user’);

You have completed your register code also in laravel. Now the time for getting our proper output. Lets go to our browser and type your desire uri…

I am using http://localhost/php/laravel/laravel-learn/public/users
Now, I am getting the output from the index function “This is Our Index Page”. Yes, right I am. Now, let’s check the login page. If I change the uri http://localhost/php/laravel/laravel-learn/public/users/login

Yes, I am seeing the proper out here also.

It’s prove that, our controller is working properly and our controller is resisted also.

Yes, this is the basic way to write simple code on controller and register your controller into route. Thanks for reading this tuts. Bye for now…

Advertisements

2 Comments

  1. Hello Asif
    Thanks for your concert about this. Have you checked the laravel directory properly? For all the you have to go your laravel directory/application. Now for the route.php file, go to the bottom of and find out the route.php file beside the start & bundle.php files.

    If you have any more queries, then write me again.
    Thanks for reading….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s