Meta information and article body cast
This commit is contained in:
@@ -32,6 +32,17 @@ class Article extends Model
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'body' => 'array',
|
||||
'meta' => 'array'
|
||||
];
|
||||
|
||||
public function source()
|
||||
{
|
||||
return $this->belongsTo(Source::class);
|
||||
|
@@ -55,6 +55,9 @@ class ScrapeMihaaruCommand extends Command
|
||||
"body" => $article["content"],
|
||||
"guid" => $article["guid"],
|
||||
"published_date" => $article["date"],
|
||||
"meta" => [
|
||||
"title" => $article["og_title"]
|
||||
]
|
||||
|
||||
]);
|
||||
|
||||
|
@@ -6,6 +6,7 @@ use App\Http\Resources\SourceResource;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Source;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Resources\ArticleResource;
|
||||
|
||||
class SourcesController extends Controller
|
||||
{
|
||||
@@ -28,7 +29,7 @@ class SourcesController extends Controller
|
||||
{
|
||||
return response()->json([
|
||||
'source' => new SourceResource($source),
|
||||
'articles' => $source->articles()->paginate(8)
|
||||
'articles' => ArticleResource::collection($source->articles()->paginate(8))
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ class ArticleResource extends JsonResource
|
||||
"id" => $this->id,
|
||||
"title" => $this->title,
|
||||
"author" => $this->author,
|
||||
"meta" => $this->meta,
|
||||
"featured_image" => $this->featured_image,
|
||||
"url" => $this->url,
|
||||
"body" => $this->body,
|
||||
@@ -28,8 +29,8 @@ class ArticleResource extends JsonResource
|
||||
"source" => new SourceResource($this->source),
|
||||
"topics" => TopicResource::collection($this->topics),
|
||||
"link" => url(route('article.show',$this->id)),
|
||||
"published_date" => $this->published_date,
|
||||
"meta" => $this->meta
|
||||
"published_date" => $this->published_date
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -43,11 +43,8 @@ class MihaaruScraper
|
||||
$this->author = $cleaneddata;
|
||||
});
|
||||
|
||||
$crawler->filter('article')->each(function ($node) {
|
||||
$content = $node->text();
|
||||
|
||||
$input = str_replace("\n", '', $content);
|
||||
$this->content = $input;
|
||||
$crawler->filter('article p')->each(function ($node) {
|
||||
$this->content[] = preg_replace("/[a-zA-Z]/","",$node->text());
|
||||
});
|
||||
|
||||
$crawler->filter('.article-tags')->each(function ($node) {
|
||||
|
@@ -13,6 +13,6 @@ use Illuminate\Support\Facades\Route;
|
||||
|
|
||||
*/
|
||||
|
||||
Route::get('/{any?}', function () {
|
||||
Route::get('{path}', function () {
|
||||
return view('app');
|
||||
});
|
||||
})->where('path', '(.*)');
|
Reference in New Issue
Block a user