limit(10)->get(); return $news; } public function list( ?int $page = 1) { $paginatedData = News::orderByDesc('created_at')->paginate(10, ['*'], '', $page); $results = $paginatedData->map(fn($item) => (Object)$item->toArray())->map(function($article){ $article->title = Str::limit($article->title, 60); $article->body = Str::limit($article->body, 150); $article->meta['image'] = Helpers::getImageFullUrl( $article->meta['image'], 320, 180); return $article; }); // dd($results); $meta['title'] = config('site.news.list.title', 'Popular Movies'); $meta['description'] = config('site.news.list.description', 'Popular Movies'); $meta['image'] = asset('assets/images/fb-capture.png'); $meta['route'] = 'news'; $pagination = ['total' => $paginatedData->lastPage(), 'page' => $page]; $data = $results; if (defined('SHOULD_PRERENDER')) { return view('prerender.list', compact('data', 'pagination', 'meta')); } $pagination = self::encodeForInertia($pagination); $data = self::encodeForInertia($data ?? []); $meta = self::encodeForInertia($meta ?? []) ; return Inertia::render('News', compact('data', 'pagination', 'meta')); } /** * Display the specified resource. * * @param \App\Models\News $news * @return \Illuminate\Http\Response */ public function show(News $news, $slug, $id) { $article = (Object)$news->find($id)->toArray(); dd($article); if (defined('SHOULD_PRERENDER')) { return view('prerender.list', compact('data', 'pagination', 'meta')); } return Inertia::render('News', compact('data', 'pagination', 'meta')); } /** * Show the form for editing the specified resource. * * @param \App\Models\News $news * @return \Illuminate\Http\Response */ public function edit(News $news) { // } /** * Update the specified resource in storage. * * @param \App\Http\Requests\UpdateNewsRequest $request * @param \App\Models\News $news * @return \Illuminate\Http\Response */ public function update(UpdateNewsRequest $request, News $news) { // } /** * Remove the specified resource from storage. * * @param \App\Models\News $news * @return \Illuminate\Http\Response */ public function destroy(News $news) { // } /** * @return JsonResponse */ public function importFromRemoteProvider() { app(ImportNewsFromRemoteProvider::class)->execute(); return $this->success(); } }