Пример #1
0
     \App\Models\Articles::create(['article_title' => '文章測試Facade', 'article_content' => '這是一篇測試文章,第Facade篇。', 'feature' => rand(0, 1), 'page_view' => rand(0, 200), 'created_at' => Carbon::now('Asia/Taipei'), 'updated_at' => Carbon::now('Asia/Taipei')]);
     echo "Facade!!<br />";
     // 使用new建構式
     $post = new \App\Models\Articles();
     $post->article_title = '文章測試new';
     $post->article_content = '這是一篇測試文章,第new篇。';
     $post->feature = rand(0, 1);
     $post->page_view = rand(0, 200);
     $post->created_at = Carbon::now('Asia/Taipei');
     $post->updated_at = Carbon::now('Asia/Taipei');
     $post->save();
     echo "new!!<br />";
 }]);
 Route::get('search', ['as' => 'ORM.search', function () {
     // 收尋資料
     $data = \App\Models\Articles::all();
     // var_dump($data);
     // exit();
     dd($data);
     // 條件收尋
     $data = \App\Models\Articles::where('feature', '=', true)->orderBy('id')->get();
     // dd($data);
 }]);
 Route::get('update', ['as' => 'ORM.update', function () {
     // 更新資料
     $data = \App\Models\Articles::find(1);
     $data->update(['article_title' => 'update test.', 'feature' => true]);
     $data = \App\Models\Articles::where('id', '=', 10);
     $data->update(['article_title' => 'update test=3=.', 'feature' => false]);
     // save方法
     $data = \App\Models\Articles::where('id', '=', 11)->first();
 public function delete($slug)
 {
     if (Input::has('selected_article')) {
         return Redirect::to('admin/articles/' . Input::get('selected_article') . '/delete');
     } else {
         if (Input::has('confirmed_delete')) {
             try {
                 $article = Articles::where($slug, $slug)->get();
                 Articles::where('slug', $slug)->get()->delete();
                 return View::make('admin.articles.delete', ['status' => 'successful', 'article' => $article, 'articles' => Articles::all(), 'id' => $article->id]);
             } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
                 return View::make('admin.articles.delete', ['status' => 'unsuccessful', 'article' => $article, 'id' => $id]);
             }
         } else {
             $article = Articles::where('slug', $slug);
             return View::make('admin.articles.delete', ['status' => 'confirm', 'article' => $article, 'articles' => Articles::all(), 'id' => $id]);
         }
     }
 }
Пример #3
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $qArticles = Articles::all();
     return view('admin.article.index', compact('qArticles'));
 }