Add route
Copy Code code as follows:
Route::get (' artiles ', ' articlescontroller@index ');
Creating a Controller
Copy Code code as follows:
PHP Artisan Make:controller Articlescontroller--plain
Modify Controller
<?php namespace App\http\controllers;
Use app\article;
Use app\http\requests;
Use App\http\controllers\controller;
Use Illuminate\http\request;
Class Articlescontroller extends Controller {public
function index () {
$articles = Article::all ();
return $articles;
}
You can see the returned JSON results in the browser, cool!
Modify controller, return view
The Public Function index () {
$articles = Article::all ();
Return view (' Articles.index ', compact (' articles '));
}
Create a View
@extends (' layout ')
@section (' content ')
Browse results, cool!!!!
Show individual articles
To add a route that displays detailed information
Copy Code code as follows:
Route::get (' Articles/{id} ', ' articlescontroller@show ');
where {ID} is a parameter that represents the ID of the article to display, modify the controller:
Public function Show ($id) {
$article = Article::find ($id);
If you cannot find the article
if (Is_null ($article))
{
//Production environment App_debug=false
abort (404);
}
Return view (' Articles.show ', compact (' article '));
}
Laravel provides a more convenient function to modify the controller:
Public function Show ($id) {
$article = Article::findorfail ($id);
Return view (' Articles.show ', compact (' article '));
}
It ' s cool.
New View
@extends (' layout ')
@section (' content ')
Trying to access in the browser:/ARTICLES/1/ARTICLES/2
Modify the Index view
@extends (' layout ')
@section (' content ')
The above mentioned is the whole content of this article, hope to be able to learn Laravel5 frame to be helpful to everybody.