top of page

laravel(part2->Routes)

  • Writer: sondip poul singh
    sondip poul singh
  • Jan 9, 2019
  • 1 min read

take a project in sublime by dragging.when done open web.php in route. Here we can see

<?php

Route::get('/', function () { return view('welcome'); });

it says that in localhost:8000/ we get the view of welcome.blade.php. This file can be found in resource->view

we can create our own route name and own view

Route::get('/newpage', function () { return view('MyView'); });

when we write localhost:8000/newpage it shows a new page called MyView.blade.php. We must create and write code in the MyView Page in the view folder.Initially copy the welcome.blade.php code and see if it is working or not.

Awesome!!

Now it will be messy if we are writing functions in Route.So we should use "Controller" to take the control. Controller is something that interacts with the data in database and send it to the view.To make a Controller Open the git bash terminal and write

php artisan make:controller name_of_controller

It will make a controller and will be found in app->HTTP->Auth->Controller.Open the Controller(what we create earlier) and we can see

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PagesController extends Controller { public function newpage() { return view('MyView'); } }

(PagesController is the new controller we made)

the newpage function is written by us and the view and other codes can be written in it.Now let us back in the wiew and instead of writing the function now we add an array like this

Route::get('/new',[ 'uses'=>'PagesController@newpage' ]);

when user type localhost:8000/new the controller named PagesController use the function named newpage created by us and return the view.

Comentários


bottom of page