创建一个index主页列出所有文章
生成路由
app/Http/routes.php
Route::get('/articles','ArticlesController@index');
生成一个controller
php artisan make:controller ArticlesController
namespace App\Http\Controllers;use App\Articles; //当你使用Articles这个model的时候,phpstorme会帮你默认导入这个类use Illuminate\Http\Request;use App\Http\Requests;class ArticlesController extends Controller{ // public function index(){ //因为路由里面我们使用了ArticlesController@index,所以这里是index方法 $articles = Articles::all(); //这里需要注意的是这个Articles是我们创建的那个Articles的model,在phpstorme会有提示,这里的all方法是返回这个model查询到的所有数据,这些数据是提前输入好的 return $articles; }}
访问localhost:8000/articles会出现以下内容,laravel会默认返回json格式的数据
本页JSON数据由FeHelper进行自动格式化,若有任何问题,点击这里提交 意见反馈[{"id": 1,"title": "title","content": "content","publish_at": "2016-05-14 18:04:44","created_at": "2016-05-14 18:04:48","updated_at": "2016-05-14 18:04:48"},{"id": 2,"title": "title2","content": "content2","publish_at": "2016-05-15 04:24:48","created_at": "2016-05-14 18:07:42","updated_at": "2016-05-14 18:07:42"},{"id": 3,"title": "second title","content": "second content","publish_at": "2016-05-14 18:15:38","created_at": "2016-05-14 18:15:38","updated_at": "2016-05-14 18:15:38"}]
运用已有的blade知识,配置一个layout
例如
resources/views/layout/app.blade.phplayout只是一个概念,这个文件主要是为了创造一个模板容器,用来处理那些可以复用的代码,例如一些html的head,body标签
Laravel@yield('content')
查看更多关于实现简单blog展示_html/css_WEB-ITnose的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did114916