嗨段段

1145 经验值

1: workspace composer create-project laravel/laravel test
2: pa make:controller ArticlesController --model=Article
3: vi .env for database configure
4: pa make:controller ArticlesController --model=Article
5: pa serve
6: pa tinker
6: >>> App\Article::all() ---> 直接退出!!!!
7: App\Article::find(1)
7: App\Article {#685 id: xxx, title: xxx }

配置composer.json:

    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0"
    },

问题就在第六步,想不通啊。

在看实现简单Blog展示[https://www.laravist.com/series/laravel-5-basic/episodes/8],在实验到01:48处,只要执行AppArticle::all() 发现进程直接退出。
请问在5.4版本model的all是有问题的?还会让php进程直接退出?

表现在页面上的效果像下面这样(服务器居然连头部都没有返回):
The localhost page isn’t working

localhost didn’t send any data.
ERR_EMPTY_RESPONSE

下面用tinker测试:

Psy Shell v0.8.8 (PHP 7.1.4 — cli) by Justin Hileman
>>> App\Article::all();
➜  larvael 

但下面的语句却可以:

>>> App\Article::find(1);
=> App\Article {#686
     id: 1,
     title: "my First Title",
     content: "my First Content",
     published_at: "2017-07-04 07:28:08",
     created_at: "2017-07-04 07:28:34",
     updated_at: "2017-07-04 07:28:34",
   }
>>> 

我看到官网上的文档也支持AppFlight::all(); all[http://d.laravel-china.org/docs/5.4/eloquent#取回多个模型]方法的,其它的同学是否也有这个问题?

controller和model通过下面语句创建:

pa make:controller ArticlesController --model=Article

➜  larvael cat app/Http/Controllers/ArticlesController.php
<?php

namespace App\Http\Controllers;

use App\Article;
use Illuminate\Http\Request;

class ArticlesController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        return Article::all();
    }
....
➜  larvael cat app/Article.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    //
    protected $table = "articles";
}

希望大家交流交流..