diff --git a/app/Http/Controllers/ArticleController.php b/app/Http/Controllers/ArticleController.php index 2913ebb777920f4f49272bdc85af676d36b8b40b..a24ed990d131d986091ddc923d1277e967901b22 100644 --- a/app/Http/Controllers/ArticleController.php +++ b/app/Http/Controllers/ArticleController.php @@ -4,7 +4,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -use App\Models\Article; +use App\Models\Articles; // use App\Models\Logs; /* @@ -25,14 +25,15 @@ class ArticleController extends Controller } $article->content = str_replace("`", "\`", $article->content); - return view('article', ['title'=>$id, 'article'=>$article, 'id'=>$id]); + return view('article', ['title'=>$id, 'articles'=>$articles, 'classify'=>$classify, 'id'=>$id]); } // 文章列表页(主页) public function articleList() { $articles = DB::table('articles')->get(); + $classify = DB::table('classify')->get(); - return view('home', ['articles'=>$articles, 'title'=>'主页']); + return view('home', ['articles'=>$articles, 'classify'=>$classify, 'title'=>'主页']); } @@ -145,7 +146,8 @@ class ArticleController extends Controller } $article = DB::table('articles')->where('aid', $id)->first(); - return view('update', ['title'=>'文章编辑'.$id, 'article'=>$article]); + $classify = DB::table('classify')->get(); + return view('update', ['title'=>'文章编辑'.$id, 'articles'=>$articles, 'classify'=>$classify]); } // 文章修改处理 public function updateCheck($id = null) @@ -216,13 +218,15 @@ class ArticleController extends Controller public function search() { $where = $_GET['q']; - $articles = Article::where('aid', 'like', "%$where%") + $articles = Articles::where('aid', 'like', "%$where%") + ->orWhere('cid', 'like', "%$where%") + ->orWhere('uid', 'like', "%$where%") ->orWhere('title', 'like', "%$where%") ->orWhere('title2', 'like', "%$where%") ->orWhere('content', 'like', "%$where%") ->get(); - - return view('home', ['articles'=>$articles, 'title'=>'主页', 'msg'=>'Search: '.$where]); + $classify = DB::table('classify')->get(); + return view('home', ['articles'=>$articles, 'classify'=>$classify, 'title'=>'搜索', 'msg'=>'Search: '.$where]); // return response(dump($articles)); @@ -233,7 +237,9 @@ class ArticleController extends Controller public function searchAPI() { $where = $_GET['q']; - $articles = Article::where('aid', 'like', "%$where%") + $articles = Articles::where('aid', 'like', "%$where%") + ->orWhere('cid', 'like', "%$where%") + ->orWhere('uid', 'like', "%$where%") ->orWhere('title', 'like', "%$where%") ->orWhere('title2', 'like', "%$where%") ->orWhere('content', 'like', "%$where%") @@ -256,7 +262,8 @@ class ArticleController extends Controller }else{ $article = DB::table('articles')->where('aid', $id)->first(); } + $classify = DB::table('classify')->get(); - return view('api.article', ['title'=>$id, 'article'=>$article, 'id'=>$id]); + return view('api.article', ['title'=>$id, 'article'=>$article, 'classify'=>$classify, 'id'=>$id]); } } \ No newline at end of file diff --git a/app/Models/Article.php b/app/Models/Articles.php similarity index 79% rename from app/Models/Article.php rename to app/Models/Articles.php index 82f74b0eb1058a31adcfc22c56ece1e6cbb737f7..12c2f09958998f6208a1dd52f528fc16a72ee760 100644 --- a/app/Models/Article.php +++ b/app/Models/Articles.php @@ -5,10 +5,10 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -class Article extends Model +class Articles extends Model { use HasFactory; - protected $table = 'article'; + protected $table = 'articles'; protected $primaryKey = 'aid'; public $timestamps = false;//是否自动维护时间戳 } diff --git a/resources/views/custom/phpFunction.blade.php b/resources/views/custom/phpFunction.blade.php index cbfb1a789d987c04679f12800213bf26b0a451b7..8e919ca49e5d2057dcd181e931c297c745191801 100644 --- a/resources/views/custom/phpFunction.blade.php +++ b/resources/views/custom/phpFunction.blade.php @@ -19,4 +19,10 @@ } return $str; } + function objectToArray($object) { + $jsonString = json_encode($object); + $array = json_decode($jsonString, true); + + return $array; + } @endphp \ No newline at end of file diff --git a/resources/views/home/main.blade.php b/resources/views/home/main.blade.php index 6c07d9c02248db7e33a5ece1b12d6d60845cde84..62d6996004432391188dea2b1ddfcc7aa84f3364 100644 --- a/resources/views/home/main.blade.php +++ b/resources/views/home/main.blade.php @@ -1,17 +1,18 @@ {{-- resources\views\home\main.blade.php --}}
- @include('custom.phpFunction') - @foreach ($articles as $article) @php // 设置时区 date_default_timezone_set(env('USER_TIMEZONE', 'PRC')); + $classify_kv = array_column(objectToArray($classify), 'cname', 'cid'); @endphp + + @foreach ($articles as $article)
@@ -19,6 +20,7 @@
{{ cut_str($article->title, 12, '…') }}
@php + $cid = $article->cid; if ($article->title2 != null) echo cut_str($article->title2, 16, '…'); @endphp @@ -29,7 +31,7 @@ {{ cut_str($article->content, 16, '') }}

-

最后修改于:{{ date("Y-m-d H:i",$article->lastdate) }}

+

最后修改于:{{ date("Y-m-d H:i",$article->lastdate)." | $cid : $classify_kv[$cid]" }}

diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index ef108341aece61a190f70d9c7d66dda3cae51039..c80607a20d0f5bb61081ed14963101c290d0ca0f 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -36,6 +36,8 @@ text-decoration: none; cursor: pointer; } +/* (全局)补充样式 */ + code {background: #eeeeeeaa;}