Guest User

Untitled

a guest
Jun 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. Undefined property: IlluminateDatabaseEloquentBuilder::$author
  2.  
  3. class Comment extends Model
  4. {
  5.  
  6. public function author()
  7. {
  8. return $this->belongsTo('AppUser','user_id');
  9. }
  10. }
  11.  
  12. public function index(Request $request)
  13. {
  14. $comments = Comment::query()->orderby('created_at', 'DESC');
  15.  
  16. $id=$request->input('id');
  17. $name=$request->input('username');
  18.  
  19.  
  20. if(!empty($id)){
  21. $comments->where('id', $request->input('id') )->get();
  22. }
  23. if(!empty($name)){
  24. $comments->where($comments->author->username, 'LIKE', $request->input('username') )->get();
  25. }
  26. $comment = $comments->paginate(10);
  27.  
  28.  
  29. return view('comments.index')->withComment($comment);
  30. }
  31.  
  32. <div class="panel-body">
  33. {!! Form::open(['route' => 'comments.index', 'method' => 'GET']) !!}
  34. <div class="col-md-5">
  35. {!! Form::label('id', 'Search By ID:') !!}
  36. {!! Form::text('id', null, array('class' => 'form-control')) !!}
  37. </div>
  38. <div class="col-md-5">
  39. {!! Form::label('username', 'Search By Username:') !!}
  40. {!! Form::text('username', null, array('class' => 'form-control')) !!}
  41. </div>
  42. <div class="col-md-2">
  43. {!! Form::submit('Find Comments', array('class' => 'btn btn-send ')) !!}
  44. </div>
  45. {!!Form::close()!!}
  46.  
  47. </div>
  48. @foreach($comment as $comments)
  49. //data
  50. @endforeach
  51.  
  52. $comments = Comment::with(['author' => function ($query) use($request) {
  53. $query->where(username, 'LIKE', $request->input('username') )
  54. }])->orderby('created_at', 'DESC');
Add Comment
Please, Sign In to add comment