Laravel 5 Framework Entry (iii) _php instance

Source: Internet
Author: User
Tags auth

In this tutorial, we will use the Laravel 5 with the out-of-the-box Auth system to verify our background permissions, and build the front page, the pages for display.

1. Permission Verification

Background address is http://localhost:88/admin, all of our background operations will be on this page or under its subpages. With the Auth provided by Laravel 5, we can implement the privilege verification function with only a few changes to the routing code.

First, change the code for the routing group to:

Copy Code code as follows:

Route::group ([' prefix ' => ' admin ', ' namespace ' => ' admin ', ' middleware ' => ' auth '], function ()
{
Route::get ('/', ' adminhomecomtroller@index ');
Route::resource (' pages ', ' Pagescontroller ');
});

There is only one change in the code above: a ' middleware ' => ' auth ' is added to the first argument (an array) of ' Route::group '. Now access to http://localhost:88/admin, you should jump to the landing page. If there is no jump, do not panic, from the upper right corner of the exit, re-enter can be.

Our personal blog system does not want people to casually register, we will change some of the routing code, only the basic login, logoff features.

Delete:

Copy Code code as follows:

Route::controllers ([
' Auth ' => ' Auth\authcontroller ',
' Password ' => ' Auth\passwordcontroller ',
]);

Increase:

Copy Code code as follows:

Route::get (' Auth/login ', ' auth\authcontroller@getlogin ');
Route::p ost (' Auth/login ', ' auth\authcontroller@postlogin ');
Route::get (' auth/logout ', ' auth\authcontroller@getlogout ');

The background of the minimized feature with permission validation is complete, and this background currently manages only page (page) resources. Next we'll build the front page and show the pages.

2. Building the Home page

First, the routing code is sorted and the top two lines of the route are routed:

Copy Code code as follows:

Route::get ('/', ' welcomecontroller@index ');
Route::get (' Home ', ' homecontroller@index ');

Change into:

Copy Code code as follows:

Route::get ('/', ' homecontroller@index ');

We will use HomeController directly to support our front page display.

You can now delete the learnlaravel5/app/http/controllers/welcomecontroller.php controller files and learnlaravel5/resources/views/ welcome.blade.php view file.

Modify learnlaravel5/app/http/controllers/homecontroller.php to:

<?php namespace App\http\controllers;

Use App\page;

Class HomeController extends Controller {public

 Function index ()
 {return
 view (' Home ')->withpages ( Page::all ());
 }



The controller construction is complete.

' View (' home ')->withpages (Page::all ()) The following features are implemented:

Rendering learnlaravel5/resources/views/home.blade.php View Files
Pass the variable $pages into the view, $pages = Page::all ()
Page::all () calls the All () method in eloquent, which returns all the data in the pages table.
Next we start to write the view file:

First, we will create a front page of the uniform shell, the '

<! DOCTYPE html>
 
 

Modify the learnlaravel5/resources/views/home.blade.php file as:

@extends (' _layouts.default ')

@section (' content ')
 <div id= "title" style= "Text-align:center;" >
  
 

The first line ' @extends (' _layouts.default ') ' represents the learnlaravel5/resources/views/_layouts/default.blade.php view of this page. The Laravel view rendering system first loads the parent view and then renders the contents of the @section (' content ') in this view into the @yield (' content ') in the parent view.

To access http://localhost:88/, you can get the following page:

2. Building page Display pages

First, increase the route. Add a row below the first line of the routing file:

Copy Code code as follows:

Route::get (' Pages/{id} ', ' pagescontroller@show ');

New controller learnlaravel5/app/http/controllers/pagescontroller.php, responsible for the display of a single page:

<?php namespace App\http\controllers;

Use App\page;

Class Pagescontroller extends Controller {public

 function Show ($id)
 {return
  view (' Pages.show ')-> Withpage (Page::find ($id));
 }



New View learnlaravel5/resources/views/pages/show.blade.php file:

@extends (' _layouts.default ')

@section (' content ')
  
 

All completed, inspection results: Click on the title of any article in the homepage, enter the article display page, you will see the following page:

At this point, the front end of the presentation page is complete, tutorial three ended.

The above mentioned is the whole content of this article, hope to be able to learn Laravel5 frame to be helpful to everybody.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.