There are 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.
- Go to in the "c:\wamp\www\" folder
- Open command window and cd in "c:\wamp\www\"
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. - Rename "server.php" to "index.php"
- 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".
- 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/
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/
Nice Information about for create a controller in laravel is very good
ReplyDelete