Route::get('test3','PhotoController@test3');
public function test3(){
$res = PhotoModel::all();
dd($res);
}
$res = PhotoModel::find(2);
dd($res);
$res = PhotoModel::findOrFail('2');
dd($res);
$res = PhotoModel::get();
dd($res);
$res = PhotoModel::where('Id','>','20')->orderBy('age','desc')->first();
dd($res);
PhotoModel::chunk(2,function($res){
echo '<pre>';
var_dump($res);
echo '</pre>';
});
object(Illuminate\Database\Eloquent\Collection)
["items":protected]=>
array(2) {
[0]=>
object(App\PhotoModel)
["table":protected]=>
string(5) "photo"
["primaryKey":protected]=>
string(2) "Id"
["connection":protected]=>
string(5) "mysql"
["keyType":protected]=>
string(3) "int"
["incrementing"]=>
bool(true)
["with":protected]=>
array(0) {
}
["withCount":protected]=>
array(0) {
}
["perPage":protected]=>
int(15)
["exists"]=>
bool(true)
["wasRecentlyCreated"]=>
bool(false)
["attributes":protected]=>
array(5) {
["id"]=>
int(1)
["src"]=>
string(2) "as"
["age"]=>
int(99)
["created_at"]=>
string(19) "2018-08-20 03:44:49"
["updated_at"]=>
string(19) "2018-08-20 03:44:49"
}
["original":protected]=>
array(5) {
["id"]=>
int(1)
["src"]=>
string(2) "as"
["age"]=>
int(99)
["created_at"]=>
string(19) "2018-08-20 03:44:49"
["updated_at"]=>
string(19) "2018-08-20 03:44:49"
}
["changes":protected]=>
array(0) {
}
["casts":protected]=>
array(0) {
}
["dates":protected]=>
array(0) {
}
["dateFormat":protected]=>
NULL
["appends":protected]=>
array(0) {
}
["dispatchesEvents":protected]=>
array(0) {
}
["observables":protected]=>
array(0) {
}
["relations":protected]=>
array(0) {
}
["touches":protected]=>
array(0) {
}
["timestamps"]=>
bool(true)
["hidden":protected]=>
array(0) {
}
["visible":protected]=>
array(0) {
}
["fillable":protected]=>
array(0) {
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
}
[1]=>
object(App\PhotoModel)
["table":protected]=>
string(5) "photo"
["primaryKey":protected]=>
string(2) "Id"
["connection":protected]=>
string(5) "mysql"
["keyType":protected]=>
string(3) "int"
["incrementing"]=>
bool(true)
["with":protected]=>
array(0) {
}
["withCount":protected]=>
array(0) {
}
["perPage":protected]=>
int(15)
["exists"]=>
bool(true)
["wasRecentlyCreated"]=>
bool(false)
["attributes":protected]=>
array(5) {
["id"]=>
int(2)
["src"]=>
string(10) "hm2FX3iRsl"
["age"]=>
int(26)
["created_at"]=>
string(19) "2018-08-20 03:44:49"
["updated_at"]=>
string(19) "2018-08-20 03:44:49"
}
["original":protected]=>
array(5) {
["id"]=>
int(2)
["src"]=>
string(10) "hm2FX3iRsl"
["age"]=>
int(26)
["created_at"]=>
string(19) "2018-08-20 03:44:49"
["updated_at"]=>
string(19) "2018-08-20 03:44:49"
}
["changes":protected]=>
array(0) {
}
["casts":protected]=>
array(0) {
}
["dates":protected]=>
array(0) {
}
["dateFormat":protected]=>
NULL
["appends":protected]=>
array(0) {
}
["dispatchesEvents":protected]=>
array(0) {
}
["observables":protected]=>
array(0) {
}
["relations":protected]=>
array(0) {
}
["touches":protected]=>
array(0) {
}
["timestamps"]=>
bool(true)
["hidden":protected]=>
array(0) {
}
["visible":protected]=>
array(0) {
}
["fillable":protected]=>
array(0) {
}
["guarded":protected]=>
array(1) {
[0]=>
string(1) "*"
}
}
}
}
public function test3(){
// $res = PhotoModel::all();
// dd($res);//集合
// $res = PhotoModel::find(2);
// dd($res);//模型对象
// $res = PhotoModel::findOrFail('2');//2 99 没有会报错
// dd($res);//模型对象
// $res = PhotoModel::get();
// dd($res);
// $res = PhotoModel::where('Id','>','20')->orderBy('age','desc')->first();
// dd($res);
// PhotoModel::chunk(2,function($res){
// echo '<pre>';
// var_dump($res);
// echo '</pre>';
// });//一次查询两条数据
// $res = PhotoModel::count();
// var_dump($res);
//
// $res = PhotoModel::max('age');
// var_dump($res);
//
// $res = PhotoModel::min('age');
// var_dump($res);
//
// $res = PhotoModel::sum('age');
// var_dump($res);
//
// $res = PhotoModel::avg('age');
// var_dump($res);
}