Sometimes you may need to create more advanced where clauses such as "where exists" or nested parameter groupings. The Laravel query builder can handle these as well:1DB::table('users') 2 ->where('name', '=', 'John') 3 ->orWhere(function($query) 4 { 5 $query->where('votes',...
You may begin searching a model using the search method. The search method accepts a single string that will be used to search your models. You should then chain the get method onto the search query to retrieve the Eloquent models that match the given search query:1use App\Models\Order; ...
For cards that display information about your users, such as the Application Usage card, Pulse will only record the user's ID. When rendering the dashboard, Pulse will resolve the name and email fields from your default Authenticatable model and display avatars using the Gravatar web service....
Since each Eloquent model serves as a query builder, you may also add constraints to queries, and then use the get method to retrieve the results:1$flights = App\Flight::where('active', 1) 2 ->orderBy('name', 'desc') 3 ->take(10) 4 ->get();...
You may begin searching a model using the search method. The search method accepts a single string that will be used to search your models. You should then chain the get method onto the search query to retrieve the Eloquent models that match the given search query:1use App\Models\Order; ...
The user method accepts a closure which will receive the Authenticatable model to be displayed and should return an array containing name, extra, and avatar information for the user:1use Laravel\Pulse\Facades\Pulse; 2 3/** 4 * Bootstrap any application services. 5 */ 6public function boot...
However, the query builder's cursor method returns a LazyCollection instance. This allows you to still only run a single query against the database but also only keep one Eloquent model loaded in memory at a time. In this example, the filter callback is not executed until we actually ...
4 * @param \Illuminate\Database\Eloquent\Builder $query 5 * @return \Illuminate\Database\Eloquent\Builder 6 */ 7protected function makeAllSearchableUsing($query) 8{ 9 return $query->with('author'); 10}Adding RecordsOnce you have added the Laravel\Scout\Searchable trait to a model, all yo...
return[newModelScope('listByUser'), ]; 上面的代码会在执行的时候,会调用模型的 scopeListByUser 方法。 如果需要传参: 上面的代码等同于 function(Builder$q) {$q->older(60); }, When 对象操作 return['id'=> When::make(true)->success('34'),'url'=> When::make(false)->success('http://ww...
If you do not want to retrieve the model before deleting the record, you may use theunsearchablemethod on an Eloquent query instance or collection: 1//Removing via Eloquent query... 2App\Order::where('price','>',100)->unsearchable(); ...