Ok与&和&&等价于布尔值。
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use \App\Location;
class AjaxLocationsController extends Controller
{
public function index(Request $request)
{
$searchquery = $request->searchquery;
$states = collect();
$countries = collect();
$all_details = collect();
$counter = 0;
$locations = Location::select('id', 'location', 'parent_id')
->where([['id', '>', 4351], ['location', 'like', '%' . $searchquery . '%']])
->orderBy('location')
->get();
foreach ($locations as $location)
{
$state = Location::select('id as state_id', 'location as state', 'parent_id as state_parent_id')
->where('id', '=', $location->parent_id)
->get();
$states->push($state);
}
$states = $states->flatten();
foreach ($states as $state)
{
$country = Location::select('id as country_id', 'location as country')
->where('id', '=', $state->state_parent_id)
->get();
$countries->push($country);
}
$countries = $countries->flatten();
foreach ($locations as $location)
{
$full_location = collect([
'id' => $location->id,
'location' => $location->location,
'parent_id' => $location->parent_id,
'state_id' => $states[$counter]['state_id'],
'state' => $states[$counter]['state'],
'state_parent_id' => $states[$counter]['state_parent_id'],
'country_id' => $countries[$counter]['country_id'],
'country' => $countries[$counter]['country'],
]);
$all_details = $all_details->push($full_location);
$counter++;
}
return $all_details;
}
}
Vue Component
<template>
<div>
<label for="searchquery">Town</label>
<input type="text" v-model="searchquery" v-on:keyup="getLocations" class="form-
control">
<div class="panel-footer" v-if="data_results.length">
<ul class="list-group">
<a href="#" @click="setLocation(result)" class="list-group-item list-
group-item-action" v-for="result in data_results" :key="result.id">{{ result.location
}}, {{ result.state }}, {{ result.country }}</a>
</ul>
</div>
</div>
</template>
<script>
export default {
data() {
return {
searchquery: '',
data_results: []
}
},
methods: {
getLocations() {
this.data_results = [];
if (this.searchquery.length > 1) {
axios.get('/get-locations', { params: { searchquery: this.searchquery } })
.then(response => {
console.log(response);
this.data_results = response.data;
});
}
},
setLocation(result) {
this.searchquery = result.location + ', ' + result.state + ', ' + result.country;
this.data_results = [];
}
},
}
</script>
两者看起来都一样。有什么区别吗?是一个更快,等等吗?