0

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

3
  • 4
    Why would you do a db query in your view layer? Commented May 18, 2017 at 9:05
  • There is no ->get() on ->first() Commented May 18, 2017 at 9:09
  • @Maerlyn, well I can actually do it from the controller. It's supposed to work both ways, right? Alex, you mean to say I can't have the two in the same syntax? Commented May 18, 2017 at 9:11

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

it's actually saying this in the PDOException "Expression #1 of SELECT list is not in GROUP BY clause"...Does that relate?
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.