QueryException, ErrorException and PDOException in Connection.php

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">                           
            {{ AppStudentHistory::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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

  • 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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x