Meta information and article body cast

This commit is contained in:
2020-08-10 21:23:16 +05:00
parent 51076aca33
commit 8d8e174095
6 changed files with 23 additions and 10 deletions

View File

@@ -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);

View File

@@ -55,6 +55,9 @@ class ScrapeMihaaruCommand extends Command
"body" => $article["content"],
"guid" => $article["guid"],
"published_date" => $article["date"],
"meta" => [
"title" => $article["og_title"]
]
]);

View File

@@ -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))
]);
}
}

View File

@@ -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
];
}
}

View File

@@ -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) {

View File

@@ -13,6 +13,6 @@ use Illuminate\Support\Facades\Route;
|
*/
Route::get('/{any?}', function () {
Route::get('{path}', function () {
return view('app');
});
})->where('path', '(.*)');