php - Laravel strange query doesn't want to work -


i'm trying username of table comments, doesn't work good.

first of all, when execute query

select `comments`.`username` `comments` inner join `threads` on `comments`.`tid` = `threads`.`tid` `comments`.`deleted_at` null , `threads`.`cid` = 4 order `comments`.`posted_at` desc limit 1 

it return value needs return.

remind, number 4 in query stands int();

now tried many things work propperly in laravel, doesn't...

so have foreach loop in view , needs display username comments.username.

how can this.

every time try array sting, or else.

the id cid called $categorie->id.

this code:

@foreach($categories $categorie)               @if($categorie->fid == $forum->fid)               <td class="topic-marker-forum">                 <i class="fa fa-comments fa-3x"></i>               </td>                <td class="col-md-6 col-sm-6">                 <div><a href="categorie-{{ str::slug($categorie->name) }}" title="{{ $categorie->name }}"><strong>{{ $categorie->name }}</strong></a></div>                 <div class=""><em>{{ $categorie->description }}</em></div>                </td>                <td class="col-md-1 col-sm-1 text-right"><span class="badge">{{ thread::where('cid', '=', $categorie->id)->remember(15)->count() }}</span></td>                <td class="col-md-4 col-sm-4 ">                 <div>                   @if(thread::where('cid', '=', $categorie->id)->exists() && comment::join('threads', 'comments.tid', '=', 'threads.tid')->where('threads.cid', '=', $categorie->id)->orderby('comments.posted_at', 'desc')->exists())                     <a href="{{ config::get('app.url') }}/thread-{{ thread::where('cid', '=', $categorie->id)->orderby('date_posted', 'desc')->pluck('slug') }}">{{ helper::htmlfilter(thread::where('cid', '=', $categorie->id)->orderby('date_posted', 'desc')->pluck('title')) }}</a><br>                      <i class="fa fa-clock-o"></i> {{ \carbon\carbon::createfromformat('y-m-d h:i:s', comment::join('threads', 'comments.tid', '=', 'threads.tid')->where('threads.cid', '=', $categorie->id)->orderby('comments.posted_at', 'desc')->pluck('posted_at'))->format('d/m/y h:i') }}<br>                      <i class="fa fa-user"></i> <a href="{{ config::get('app.url') }}/user-query here">query here</a>                   @else                   <b>-</b>                   @endif                 </div>               </td>             </tr>             @endif             @endforeach 

i don't know how can solve problem.


edit

controller (forumcontroller):

public function index()     {         $forums = forums::orderby('disp_order', 'asc')->get();         $categories = categorie::orderby('disp_order', 'asc')->get();          return view::make('index')->with('forums', $forums)->with('categories', $categories);     } 

models:

class comment extends eloquent {     use softdeletingtrait;      protected $dates = ['deleted_at'];      protected $table = 'comments';      public $timestamps = false;      public function user()     {         return $this->belongsto('user', 'uid');     }  } 

class thread extends eloquent {     use softdeletingtrait;      protected $dates = ['deleted_at'];      protected $table = 'threads';      public $timestamps = false; } 

the error when this:

{{ db::statement('select `comments`.`username` `comments` inner join `threads` on `comments`.`tid` = `threads`.`tid` `comments`.`deleted_at` null , `threads`.`cid` = '. $categorie->id .' order `comments`.`posted_at` desc limit 1') }} 

this returns 1 need username.

when this:

{{comment::join('threads', 'comments.tid', '=', 'threads.tid')->where('threads.cid', '=', $categorie->id)->orderby('comments.posted_at', 'desc')->limit(1)->pluck('username')}} 

error:

sqlstate[23000]: integrity constraint violation: 1052 column 'username' in field list ambiguous (sql: select `username` `comments` inner join `threads` on `comments`.`tid` = `threads`.`tid` `comments`.`deleted_at` null , `threads`.`cid` = 3 order `comments`.`posted_at` desc limit 1) 

when use this:

{{comment::join('threads', 'comments.tid', '=', 'threads.tid')->where('threads.cid', '=', $categorie->id)->orderby('comments.posted_at', 'desc')->first()->pluck('username')}} 

it doesn't return error, doesn't display correct value?


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -