Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Hi, Jibran here.

You Statement Should be;

result = DB::table('yourtablename')->where('yourcolumn','value')->groupBy('column','column')->get();

return compact('result');

Or Use Raw Query

$users = DB::table('users')
                     ->select(DB::raw('count(*) as user_count, status'))
                     ->where('status', '<>', 1)
                     ->groupBy('status')
                     ->get();

Read about Laravel Query Builder

http://laravel.com/docs/5.1/queries

Last updated 8 years ago.
0

Thanks Jibran! but now it returns a message "Undefined property: stdClass::$result", I don't understand what it means.

and I run this query with eloquent model,

result::where('slug','=',$slug)->groupBy('vote')->first()->count();

but it return "Trying to get property of non-object"

and this is my view

@extends('master')
@section('title', 'View a question')
@section('content')

    <div class="container col-md-8 col-md-offset-2">
            <div class="well well bs-component">
			
			
					@foreach($result as $result)
                                <tr>
                                    <td>{!! $result->id !!} </td>
                                    <td>{!! $result->vote !!}</td>
                                    <td>{!! $result->slug  !!}</td>
									<td>{!! $result->count  !!}</td>
								</tr>
                            @endforeach
							
					
				
			
                   </div>

@endsection
Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

iqrasadra iqrasadra Joined 6 Dec 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.