Meta data and article resources in topic,source

This commit is contained in:
2020-08-10 19:12:28 +05:00
parent ab1f003a6d
commit 51076aca33
4 changed files with 6 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use App\Topic; use App\Topic;
use App\Http\Resources\TopicResource; use App\Http\Resources\TopicResource;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use App\Http\Resources\ArticleResource;
class TopicsController extends Controller class TopicsController extends Controller
{ {
@@ -30,7 +31,7 @@ class TopicsController extends Controller
{ {
return response()->json([ return response()->json([
'topic' => new TopicResource($topic), 'topic' => new TopicResource($topic),
'articles' => $topic->articles()->paginate(8) 'articles' => ArticleResource::collection($topic->articles()->paginate(8))
]); ]);
} }
} }

View File

@@ -28,7 +28,8 @@ class ArticleResource extends JsonResource
"source" => new SourceResource($this->source), "source" => new SourceResource($this->source),
"topics" => TopicResource::collection($this->topics), "topics" => TopicResource::collection($this->topics),
"link" => url(route('article.show',$this->id)), "link" => url(route('article.show',$this->id)),
"published_date" => $this->published_date "published_date" => $this->published_date,
"meta" => $this->meta
]; ];
} }
} }

View File

@@ -63,6 +63,7 @@ class MihaaruScraper
$data = [ $data = [
'source' => 'Mihaaru', 'source' => 'Mihaaru',
'title' => $this->title, 'title' => $this->title,
'og_title' => $crawler->filter('meta[property*="og:title"]')->first()->attr('content'),
'image' => $this->image, 'image' => $this->image,
'content' => $this->content, 'content' => $this->content,
'url' => $url, 'url' => $url,

View File

@@ -23,6 +23,7 @@ class CreateArticlesTable extends Migration
$table->string("guid")->nullable(); $table->string("guid")->nullable();
$table->unsignedBigInteger('source_id'); $table->unsignedBigInteger('source_id');
$table->dateTime('published_date'); $table->dateTime('published_date');
$table->json('meta')->nullable();
$table->timestamps(); $table->timestamps();
}); });
} }