For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Thursday, March 12, 2015

How to create controller in Laravel

The two methods to create controller in Laravel.
A) By command prompt using "artisan controller:make" :
B) By manually creating controller.
To configure Laravel look here

A) By command prompt using "artisan controller:make" :
I am assuming you are using wamp 2.5.

1- Go to in the "c:\wamp\www\" folder
    Open command window and cd in "c:\wamp\www\"
 
2- type "composer create-project laravel/laravel TestPro1" in command window;
where composer is the exe file name "create-project" is the keywors, "laravel/laravel" is the keyword, "TestPro1" is the project name.
    This will create a folder "TestPro1" with supporting directories and files.
  
3- Rename "server.php" to "index.php"
  
4- Open command prompt in "d:\wamp\www\TestPro1" and type the                                 
"php artisan controller:make MyController".
*Keep in mind that you must in the directory "TestPro1" when you issue the command in command window                            "php artisan controller:make MyController" and there must be a file "artisan", "composer.json", "composer.lock".
    This will create a file "MyController.php" in the "TestPro1\app\controllers".

5- Replace it's index() method as below
    public function index()
        {
             return "This is my web page in Laravel";
        }
    and register it by "Route::resource('welcome','WelcomeController');" in "routes.php" under "D:\wamp\www\TestPro1\app" folder.
    now you can see page content y http://localhost:/TestPro1/

B) By manually creating controller.
Goto "d:\wamp\www\TestPro1\app\controllers" folder. create a file "MyController.php". and paste listed below content.

<?php
class MyController extends \BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        //
        return "This is my web page in Laravel";
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store()
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */

public function show($id)
    {
        //
    }
    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
        //
    }

 /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function update($id)
    {
        //
    }

 /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        //
    }
}

and register it by "Route::resource('welcome','WelcomeController');" in "routes.php" under "D:\wamp\www\TestPro1\app" folder.
now you can see page content y http://localhost:/TestPro1/
Share:

0 comments:

Post a Comment

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip

Blog Archive