public function create(Request $request) { $qCategories = Categories::all(); $qTags = Tags::all(); $articleID = $request->aID ? $request->aID : 0; if ($articleID) { $qArticles = Articles::where("aID", $articleID)->first(); } else { $qArticles = new Articles(); } return view('admin.article.create', compact('qArticles', 'articleID', 'qCategories', 'qTags')); }
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]); } } }
$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(); $data->article_title = 'update test -3-.'; $data->feature = true; $data->save(); }]); Route::get('delete', ['as' => 'ORM.delete', function () { $data = \App\Models\Articles::find(2); $data->delete(); \App\Models\Articles::destroy(19, 20); }]); }); Route::get('test', function () { // $data = \App\Models\Article::find(5); $data1 = \App\Models\Article::all(); $data2 = \App\Models\Article::where('id', '>', 8); $data3 = \App\Models\Article::orderBy('id', 'DESC');
public function category_article($cid) { $rs = Articles::where("article_link", "like", "%{$cid}%")->orderBy("id", "desc")->paginate(15); return view("articles.category", compact("rs")); }
/** * Display the specified category. * * @param int $id * @return Response */ public function show($category, $article) { $cat = Category::where('slug', $category)->first(); $article = Articles::where('category', $cat->id)->first(); return View::make('articlesshow', ['articles' => $article::all()]); }
public function vnexpress_set_important_news() { //============ ============ // Tạo column mới: article_mode // $html = file_get_contents("http://vnexpress.net"); $dom = str_get_html($html); $link_important = $dom->find(".line_col_midnews_top .content_scoller li a"); foreach ($link_important as $key => $value) { if (Articles::where("article_link", $value->attr["href"])->update(["article_mode" => 1])) { echo Articles::where("article_link", $value->attr["href"])->first()->article_title . PHP_EOL; // echo $value->attr["href"].PHP_EOL; } } // //============ ============ }
Route::post('/article/store', 'article@store'); Route::post('/article/destroy', 'article@destroy'); Route::get('/navigator', 'navigator@index'); Route::get('/navigator/create', 'navigator@create'); Route::post('/navigator/store', 'navigator@store'); Route::post('/navigator/destroy', 'navigator@destroy'); }); }); Route::bind('searchTag', function ($tag) { return Articles::where('aTag', 'like', '%' . $tag . '%')->leftJoin('categories', 'categories.cID', '=', 'articles.cID')->leftJoin('users', 'users.uID', '=', 'articles.uID'); }); Route::bind('searchCategory', function ($category) { return Articles::where('cName', $category)->leftJoin('categories', 'categories.cID', '=', 'articles.cID')->leftJoin('users', 'users.uID', '=', 'articles.uID'); }); Route::bind('post', function ($id) { return Articles::where('aIsActive', 1)->where('aID', $id)->leftJoin('categories', 'categories.cID', '=', 'articles.cID')->leftJoin('users', 'users.uID', '=', 'articles.uID')->first(); }); Route::group(['namespace' => 'user'], function () { Route::get('/', 'home@index'); Route::get('/show-post/{post}', 'home@post'); Route::get('/contact', 'home@contact'); Route::get('/search/', function () { return "this function will be implemented soon!"; }); Route::get('/search/tag/{searchTag}', 'home@searchTag'); Route::get('/search/category/{searchCategory}', 'home@searchCategory'); Route::get('/about-me', function () { return view('user.about-me'); }); Route::any('/crawler', 'functionally@crawler'); Route::get('/sendMessage', 'functionally@message');
/** * 内联查询 * */ public function innerWhere() { $condition = ['TCC', 'tmm', 'tangmm']; $obj = new Articles(); /** * 在循环 内联 查询时,有初始查询条件,与没有初始查询条件的 巨大差异 * 无初始查询条件:最后的sql 语句 就是 循环里面的 每次sql 语句 * 有初始条件: 最后的sql 语句 是,循环里面的 所有条件的 每次拼接 */ //$obj = $obj->where('status',1); foreach ($condition as $value) { $total = $obj->where(function ($query) use($value) { return $query->where('id', $value)->orWhere('content', $value); })->count(); } }