-
resources/js/modules/web/pages/home/Page.js
Open in GitHubimport React, { useLayoutEffect } from "react" import PropTypes from "prop-types" import Header from "./components/Header" import Articles from "../../../../common/articles/listing" import { articleListRequest } from '../../../article/service' export default function Page({ dispatch }) { useLayoutEffect(() => { dispatch(articleListRequest({ url: 'api/v1/articles/published' })) }, []) return <div> <Header/> <Articles/> </div> } Page.displayName = 'HomePage' Page.propTypes = { dispatch: PropTypes.func.isRequired, }
-
routes/api/articles.php
Open in GitHubuse Illuminate\Support\Facades\Route; Route::get('published', 'ArticleController@publishedArticles')->name('articles.published.index'); //
-
app/Http/Controllers/Api/ArticleController.php
Open in GitHubuse App\Models\Article; use App\Http\Controllers\Controller; class ArticleController extends Controller { // public function publishedArticles() { return Article::loadAllPublished(); } // }
-
app/Models/Article.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; use Illuminate\Contracts\Pagination\Paginator; class Article extends Model { // public static function loadAllPublished(): Paginator { return static::with([ 'user' => function (BelongsTo $query) { $query->select('id', 'name'); }, ]) ->latest() ->published() ->paginate(); } // }