public function index(){
// // we need to show all data from "blog" table
// $blogs = Blog::all();
// // show data to our view
// return view('blog.index',['blogs' => $blogs]);
$search = Request::get('search');
$blogs = Blog::where('title','like','%'.$search.'%')->orderBy('id')->paginate(6);
return view('blog.index',['blogs' => $blogs]);
}
// Why do this ..
$users=User :: where(function($query)use($value){
$query->orWhere('name','like',"{$value)")
->orWhere('email','like',"{$value}")
->orWhere('title','like',"{$value}")
->orWhere('role','like',"{$value}%")
->orWhere('status','like',"{$value}%")
})->get();
//...when you can do the same with this?
$users User :: search($value)->get();
// 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';
}