Reputation: 297
I have this piece of legacy code to return all events to the front end:
/**
* @param $request
*
* @return mixed
*/
public function index( EventsFilterRequest $request ) {
$keys = $request->all();
if ( \count( $keys ) === 0 ) {
return $this->eventsQueryBuilder()->isVisibleFor( authUser()->id )->ofOrder( 'starts_at', 'ASC' )->ofCountry( runtime()->country()->id )->ofStatus( 'future' );
}
$events = $this->eventsQueryBuilder()->isVisibleFor( authUser()->id )->ofOrder( 'starts_at', 'ASC' )->ofStatus( 'future' )->ofCountry( runtime()->country()->id );
foreach ( $keys as $key => $value ) {
if ( array_key_exists( $key, $this->_methods ) ) {
$events = $this->_methods[$key]( $events, $request, $this );
}
}
return $events;
}
In the events
table there's a column called privacy
that contains public
or private
. How can I exclude private events from being returned ?
Upvotes: 0
Views: 46
Reputation: 1693
I am new to laravel but you can use where clause in your query. Something like
$events = DB::table('events')->where('privacy', 'public')->get();
For more check this link LARAVEL QUERY
Upvotes: 1