Пример #1
0
/*
 * 修改器
 * */
Route::get('xgq', function () {
    $r = App\Article::find(1);
    $r->intro = 'ELICK';
    $r->save();
    dump($r);
});
/**
 * 日期修改器
 */
Route::get('rqxgq', function () {
    //只有在模型文件里设置 $dates 才可以直接使用Carbon类型
    //自带的created_at和updated_at不受限制 也就是不放在数组里也没关系
    $article = App\Article::find(1);
    return $article->published_at->getTimestamp();
});
/**
 * 序列号
 */
Route::get('xlh', function () {
    $user = App\User::find(1);
    //return $user->toJson();
    //return (string)$user;
    //隐藏属性这样是可以看见的
    //dump($user->password);
    return App\User::all();
});
// 认证路由...
Route::get('auth/login', 'Auth\\AuthController@getLogin');
Пример #2
0
 	UPDATING ARTICLES
 */
 // updating multiple articles
 $articles = App\Article::where('id', '<', 3);
 $articles->update(array('body' => 'test'));
 return 'Mass update!';
 // updating a single article
 $article = App\Article::find(3);
 $article->title = 'How to drive a car';
 $article->save();
 return 'Saved! New title is: ' . $article->title;
 /*
 	RETRIEVING ARTICLES
 */
 // retieving a single article by ID
 $article = App\Article::find(3);
 return $article->title;
 // retrieving multiple articles (like with QueryBuilder)
 $articles = App\Article::where('id', '>', 1)->get();
 foreach ($articles as $art) {
     var_dump($art->title);
 }
 return $articles = App\Article::all();
 foreach ($articles as $art) {
     var_dump($art->title);
 }
 return;
 /*
 	CREATING NEW ARTICLES
 */
 $article3 = App\Article::create(array('title' => 'How to ride a bike', 'body' => '...'));