如何在现有模型条件中调用或附加(连接)另一个具有条件的模型


Laravel, how to call or append(join) another model with condition in existing model condition

我被两个不同表(VenueHallVenue)的搜索功能卡住了。数据来自search1 parameter. I am able to search the data from one table (会场) but I am not able to map with another table (会场) using the existing object from the first table ( $会场

$VenueHall = VenueHall::orderBy('created_at', 'DESC');
$VenueHall = $VenueHall->with('venue');
$VenueHall = $VenueHall->with('venueType');
$VenueHall = $VenueHall->with('venue.area');
if (Input::has('query') && $searchQuery = Input::get('query'))
{
    $perecentilify = '%'. $searchQuery .'%';
    $VenueHall = $VenueHall->where(function($query) use ($perecentilify, $searchQuery) {
        $query->where('name', 'LIKE', $perecentilify)
            ->orWhere('code', 'LIKE', $perecentilify);
            //->orWhere('from venue table');
        });                 
    }
    $data = array(
        'venueHall' => $VenueHall->paginate(2)
    );
    return View::make('venues/venues', array('data' => $data));

我不能映射来自Venue表的//->orWhere('from venue table')子句。请帮我根据搜索框中的搜索值从这两个表中获取数据

在这种情况下,我经常发现连接是最简单的解决方案:

$VenueHall = VenueHall
    ::join('Venue', 'Venue.id', '=', 'VenueHall.venue_id')
    ->where('VenueHall.name', 'LIKE', $perecentilify)
    ->orWhere('VenueHall.code', 'LIKE', $perecentilify)
    ->orWhere('Venue.name', 'LIKE', $perecentilify)
    ->orderBy('created_at', 'DESC')
    ->with(['venue', 'venueType', 'venue.area'])
    ->paginate(2)
;