app/Http/routes.php
Route::get('/articles','ArticlesController@index');
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; }}
本页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"}]
例如
resources/views/layout/app.blade.phplayout只是一个概念,这个文件主要是为了创造一个模板容器,用来处理那些可以复用的代码,例如一些html的head,body标签
< !DOCTYPE html>Laravel @yield('content') @yield(('footer'))
resources/views/articles/index.blade.php
@extends('layout.app')@section('content')输出hello
@foreach($articles as $article) //循环
Copyright © 2019- ovod.cn 版权所有 湘ICP备2023023988号-4
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务