Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Undefined property: IlluminateDatabaseEloquentBuilder::$author
- class Comment extends Model
- {
- public function author()
- {
- return $this->belongsTo('AppUser','user_id');
- }
- }
- public function index(Request $request)
- {
- $comments = Comment::query()->orderby('created_at', 'DESC');
- $id=$request->input('id');
- $name=$request->input('username');
- if(!empty($id)){
- $comments->where('id', $request->input('id') )->get();
- }
- if(!empty($name)){
- $comments->where($comments->author->username, 'LIKE', $request->input('username') )->get();
- }
- $comment = $comments->paginate(10);
- return view('comments.index')->withComment($comment);
- }
- <div class="panel-body">
- {!! Form::open(['route' => 'comments.index', 'method' => 'GET']) !!}
- <div class="col-md-5">
- {!! Form::label('id', 'Search By ID:') !!}
- {!! Form::text('id', null, array('class' => 'form-control')) !!}
- </div>
- <div class="col-md-5">
- {!! Form::label('username', 'Search By Username:') !!}
- {!! Form::text('username', null, array('class' => 'form-control')) !!}
- </div>
- <div class="col-md-2">
- {!! Form::submit('Find Comments', array('class' => 'btn btn-send ')) !!}
- </div>
- {!!Form::close()!!}
- </div>
- @foreach($comment as $comments)
- //data
- @endforeach
- $comments = Comment::with(['author' => function ($query) use($request) {
- $query->where(username, 'LIKE', $request->input('username') )
- }])->orderby('created_at', 'DESC');
Add Comment
Please, Sign In to add comment