QueryException, ErrorException and PDOException in Connection.php

大兔子大兔子 提交于 2019-12-25 17:02:00

问题


I would like to ask if you can help me with the errors I am encountering with my newly installed Laravel 5.4. Here is my blade template

home.blade.php

@extends('layouts.app') @section('content') <div class="container">
<div class="row">                           
            {{ App\StudentHistory::select(['date', 'student_id', 'grade'])
            ->where('subject', 'English')
            ->groupBy('student_id')
            ->orderBy('date','desc')
            ->first()
            ->get()}}
    </div>@endsection

Let me know what else you guys need, I'll update as you ask


回答1:


  • You're trying to run a db query in your view, which is better suited in your controller.
  • You can't use first() and get() together, use one.
  • You're trying to output the query result directly, which is an object, which would throw an error even if your query was successful.



回答2:


You're doing xxx->first()->get() ...

You either call ->first() and get one object or do ->get() and get an array of objects

Reference https://laravel.com/docs/5.4/queries#retrieving-results

PS: I really can't see the advantages of doing those queries IN the view, that's missing the MVC objective of laravel.



来源:https://stackoverflow.com/questions/44043255/queryexception-errorexception-and-pdoexception-in-connection-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!