Showing posts with label Create Controller. Show all posts
Showing posts with label Create Controller. Show all posts

Thursday, November 3, 2016

Create new controller & view in laravel

Open command prompt & navigate to "C:/xampp/htdocs/laravel" (laravel is your laravel project directory) and run following command:

php artisan make:controller TestController

This command will make a controller under directory "app/Http/Controllers"

Now add the following lines to "app/Http/routes.php":
Route::resource('test', 'TestController');

Now create a file named "test.blade.php" under "resources/views" directory with following contents:
Resources/views/test.blade.php<br/>
Name found from params=<?php echo $name; ?>

Your Controller class look like following:


<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use View;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class TestController extends Controller
{
    public function index()
    {
        $data = array();
        $data["name"] = "Pritom Kumar";
        return View::make('test', $data);
    }

    public function create()
    {
        
    }

    public function store(Request $request)
    {
        
    }

    public function show($id)
    {
        
    }

    public function edit($id)
    {
        
    }

    public function update(Request $request, $id)
    {
        
    }

    public function destroy($id)
    {
        
    }
}

?>

Now you can view output by browsing following url: {LARAVEL_ROOT_URL}"/test"