I want to show comments for every specific service in my website.. the store comment method is working properly! and when I try to display comments in the blade page I get this error
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'comments.service_id' in 'where clause' (SQL: select * from comments
where comments
.service_id
= 11 and comments
.service_id
is not null) (View: C:\xampp\htdocs\dawerelzirou\resources\views\service\showservice.blade.php)
CommentsController.php (store comment)
public function store(Request $request, $services_id)
{
$this->validate($request,array(
'body'=>'required',
));
$comment=new Comment;
$comment->body=$request->body;
$comment->user_id=$request->user()->id;
$comment->services_id=$services_id;
$comment->save();
$request->session()->flash('notif','success');
return back();
}
this is comment.php
class Comment extends Model{
public function user() {
return $this->belongsTo('App\User');}
public function services() {
return $this->belongsTo('App\Service');}
}
This is Service.php
class Service extends Model{
public function user(){
return $this->belongsTo('App\User');
}
public function comments(){
return $this->hasMany('App\comment');
}
}
The blade page :
@if (count($services->comments)>0)
@foreach ($services->comments as $comment)
<div class="row">
<div class="col s6 offset-l3">
<div class="card small" style="height:auto;width:700px;">
<div class="card-content center-align">
<div class="row">
<div class="col s12">
<img src="/img/bg.jpeg" class="responsive-img circle center-align"
style="width:50%;" alt="">
</div>
<div class="row">
<div class="col s12">
<p>$comment->user->username </p>
</div>
</div>
<br>
<div class="row">
<div class="col s12">
<p>$comment->body</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endforeach
@endif
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2FRpAFh
via IFTTT
Aucun commentaire:
Enregistrer un commentaire