For smart Primates & ROBOTS (oh and ALIENS ).

Showing posts with label Laravel. Show all posts
Showing posts with label Laravel. Show all posts

Friday, March 13, 2015

Create a simple page in Laravel using Controller

Create a simple page in Laravel using Controller

1) Create a "ClientpagesController.php" file in "app/controllers/" folder as below contents

<?php
class ClientpagesController extends \BaseController {
  public function contactus(){
     return View::make("contactme");
  }
}

2) Open "app/routes.php" file and paste as:
Route::get("contactus" , "ClientpagesController@contactus");

3) Now create "contactme.php" in "app/views/" folder with any matter,
<html>
...............................
...............................
...............................
</html>

4) Now open this url in browser:
http://localhost:90/MyLaravel/public/contactus
Share:

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:

Laravel Installation and configuration

First you need to install Composer from this link:
https://getcomposer.org/download/
Here you can find both installer for windows and Unix.

If you are in windows then download here:  https://getcomposer.org/Composer-Setup.exe
Before installing Composer check that you must have PHP 5.3 or later.

    I am assuming that 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 browser with this link :
http://localhost/TestPro1/index.php

You can see default page .
Share:

How to enable debug on in Laravel

How to enable debug on in Laravel
While working with laravel Framework you could face this error "Whoops, looks like something went wrong."
To overcome this error first you need to see what is the exact error in your code. to show exact error you need to set debug true in "app.php" file.

Follow below steps:

Open "\app\config\app.php" file.
Set " 'debug' => false" to 'debug' => true

Now you can the exact error and fix the error.

Share:

Ads Inside Post

Powered by Blogger.

Archive