// Retrieve a model by its primary key...
$flight = AppModelsFlight::find(1);
// Retrieve the first model matching the query constraints...
$flight = AppModelsFlight::where('active', 1)->first();
// Shorthand for retrieving the first model matching the query constraints...
$flight = AppModelsFlight::firstWhere('active', 1);
public function index()
{
$q = Dog::query();
if (Input::has('search'))
{
// simple where here or another scope, whatever you like
$q->where('name','like',Input::get('search'));
}
if (Input::has('search-breed'))
{
$q->searchBreed(Input::get('search-breed'));
}
if (Input::has('sex'))
{
$q->where('sex', Input::get('sex'));
}
if (Input::has('radius'))
{
$q->withinRadius(Input::get('radius'));
}
$dogs = $q->orderBy(..)->paginate(5);
// ...
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
class Flight extends Model
{
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'flight_id';
}
The find Method
If you are overriding the find method in your own models and calling parent::find() within your custom method, you should now change it to call the find method on the Eloquent query builder:
public static function find($id, $columns = ['*'])
{
$model = static::query()->find($id, $columns);
// ...
return $model;
}
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
class Flight extends Model
{
/**
* The connection name for the model.
*
* @var string
*/
protected $connection = 'connection-name';
}