Building a Blog With Reactjs And Laravel Website start

Building a Blog With Reactjs And Laravel Part11: Website Start

In this article i will prepare the website front in reactjs and i will used a ready made html template to be used to display pages.

 

 

 

 

Preparing the template

Let’s prepare the html template we will use to display the components so i picked a ready made html template and removed the unnecessary css and js files and uploaded it here. After you download it extract it into public/assets/website/ directory, create this directory if it does not exist.

 

Preparing React Components

The next step is to prepare the react components so create those two directories in resources/js/website/components:

  • pages
  • partials

The pages/ directory contain the website pages. The partials/ directory contains partial components such as header and footer.

Create these components in pages/ directory:

  • Home.js
  • Category.js
  • Tag.js
  • Post.js
  • Login.js
  • Register.js

Also create these components in partials/ directory:

  • Header.js
  • Footer.js
  • Sidebar.js
  • Article.js
  • Comments.js
  • CommentForm.js

Then i setup the components with dummy data let’s update the above mentioned components as shown below:

resources/js/website/components/pages/Home.js

import React from 'react';
import Sidebar from '../partials/Sidebar';
import Article from '../partials/Article';

class Home extends React.Component
{
    constructor(props)
    {
        super(props);
    }

    render()
    {
        return (
            <div id="content-wrap">
                <div className="row">
                    <div id="main" className="eight columns">

                        <Article />
                        <Article />
                        <Article />
                        <Article />

                    </div>

                    <Sidebar/>

                </div>
            </div>
        )
    }
}

export default Home;

resources/js/website/components/pages/Category.js

import React from 'react';
import Sidebar from '../partials/Sidebar';
import Article from '../partials/Article';

class Category extends React.Component
{
    constructor(props)
    {
        super(props);
    }

    render()
    {
        return (
            <div id="content-wrap">
                <div className="row">
                    <div id="main" className="eight columns">

                        <h1>Category: News</h1>

                        <Article />
                        <Article />
                        <Article />
                        <Article />

                        <div className="pagenav">
                            <p>
                                <a rel="prev" href="#">Prev</a>
                                <a rel="next" href="#">Next</a>
                            </p>
                        </div>

                    </div>

                    <Sidebar/>

                </div>
            </div>
        )
    }
}

export default Category;

resources/js/website/components/pages/Tag.js

import React from 'react';
import Sidebar from '../partials/Sidebar';
import Article from '../partials/Article';

class Tag extends React.Component
{
    constructor(props)
    {
        super(props);
    }

    render()
    {
        return (
            <div id="content-wrap">
                <div className="row">
                    <div id="main" className="eight columns">

                        <h1>Tag: technology</h1>

                        <Article />
                        <Article />
                        <Article />
                        <Article />

                        <div className="pagenav">
                            <p>
                                <a rel="prev" href="#">Prev</a>
                                <a rel="next" href="#">Next</a>
                            </p>
                        </div>

                    </div>

                    <Sidebar/>

                </div>
            </div>
        )
    }
}

export default Tag;



resources/js/website/components/pages/Post.js

import React from 'react';
import Sidebar from '../partials/Sidebar';
import Comments from '../partials/Comments';
import CommentForm from '../partials/CommentForm';

class Post extends React.Component
{
    constructor(props)
    {
        super(props);
    }

    render()
    {
        return (
            <div id="content-wrap">
                <div className="row">
                    <div id="main" className="eight columns">

                        <article className="entry">

                            <header className="entry-header">

                                <h2 className="entry-title">
                                    We All Love Good Typography.
                                </h2>

                                <div className="entry-meta">
                                    <ul>
                                        <li>July 11, 2014</li>
                                        <span className="meta-sep">•</span>
                                        <li>
                                            <a href="#" title="" rel="category tag">Wordpress</a>,
                                            <a href="#" title="" rel="category tag">Ghost</a>
                                        </li>
                                        <span className="meta-sep">•</span>
                                        <li>Jane Doe</li>
                                    </ul>
                                </div>

                            </header>

                            <div className="entry-content-media">
                                <div className="post-thumb">
                                    <img src={process.env.MIX_APP_URL + 'assets/website/images/m-farmerboy.jpg'} />
                                </div>
                            </div>

                            <div className="entry-content">
                                <p className="lead">Lorem ipsum Nisi enim est proident est magna occaecat dolore proident eu ex sunt consectetur consectetur dolore enim nisi exercitation adipisicing magna culpa commodo deserunt ut do Ut occaecat. Lorem ipsum Veniam consequat quis aliquip dolore minim ex labore dolor Excepteur Duis velit in officia Excepteur officia officia officia cillum ut elit in fugiat incididunt ea ad Ut ut ea ea dolor ex dolor eu magna voluptate irure consectetur.</p>

                                <p>Duis ex ad cupidatat tempor Excepteur cillum cupidatat fugiat nostrud cupidatat dolor sunt sint sit nisi est eu exercitation incididunt adipisicing veniam velit id fugiat enim mollit amet anim veniam dolor dolor irure velit commodo cillum sit nulla ullamco magna amet magna cupidatat qui labore cillum sit in tempor veniam consequat non laborum adipisicing aliqua ea nisi sint ut quis proident ullamco ut dolore culpa occaecat ut laboris in sit minim cupidatat ut dolor voluptate enim veniam consequat occaecat fugiat in adipisicing in amet Ut nulla nisi non ut enim aliqua laborum mollit quis nostrud sed sed.</p>

                                <p>Lorem ipsum Nisi enim est proident est magna occaecat dolore proident eu ex sunt consectetur consectetur dolore enim nisi exercitation adipisicing magna culpa commodo deserunt ut do Ut occaecat. Lorem ipsum Veniam consequat quis aliquip dolore minim ex labore dolor Excepteur Duis velit in officia Excepteur officia officia officia cillum ut elit in fugiat incididunt ea ad Ut ut ea ea dolor ex dolor eu magna voluptate irure consectetur.</p>
                            </div>

                            <p className="tags">
                                <span>Tagged in </span>:
                                <a href="#">orci</a>, <a href="#">lectus</a>, <a href="#">varius</a>, <a href="#">turpis</a>
                            </p>

                            <ul className="post-nav group">
                                <li className="prev"><a rel="prev" href="#"><strong>Previous Article</strong> Duis Sed Odio Sit Amet Nibh Vulputate</a></li>
                                <li className="next"><a rel="next" href="#"><strong>Next Article</strong> Morbi Elit Consequat Ipsum</a></li>
                            </ul>

                        </article>

                        <div id="comments">

                            <h3>5 Comments</h3>

                            <Comments />

                            <CommentForm />

                        </div>

                    </div>

                    <Sidebar/>

                </div>
            </div>
        )
    }
}

export default Post;

resources/js/website/components/pages/Login.js

import React from 'react';
import Sidebar from '../partials/Sidebar';
import {Link} from "react-router-dom";

class Login extends React.Component
{
    constructor(props)
    {
        super(props);
    }

    render()
    {
        return (
            <div id="content-wrap">
                <div className="row">
                    <div id="main" className="eight columns">

                        <h2>Login</h2>

                        <form name="contactForm" method="post" action="">
                            <fieldset>
                                <div className="group">
                                    <label>Email</label>
                                    <input name="email" type="text" value="" placeholder="Email" />
                                </div>
                                <div className="group">
                                    <label>Password</label>
                                    <input name="password" type="password" value="" placeholder="Password" />
                                </div>

                                <button type="submit" className="submit">Login</button>
                                &nbsp;<Link to="/register">Create account</Link>
                            </fieldset>
                        </form>

                    </div>

                    <Sidebar/>

                </div>
            </div>
        )
    }
}

export default Login;

resources/js/website/components/pages/Register.js

import React from 'react';
import Sidebar from '../partials/Sidebar';
import {Link} from "react-router-dom";

class Register extends React.Component
{
    constructor(props)
    {
        super(props);
    }

    render()
    {
        return (
            <div id="content-wrap">
                <div className="row">
                    <div id="main" className="eight columns">

                        <h2>Create account</h2>

                        <form name="contactForm" method="post" action="">
                            <fieldset>
                                <div className="group">
                                    <label>Username</label>
                                    <input name="name" type="text" value="" placeholder="Name" />
                                </div>
                                <div className="group">
                                    <label>Email</label>
                                    <input name="email" type="text" value="" placeholder="Email" />
                                </div>
                                <div className="group">
                                    <label>Password</label>
                                    <input name="password" type="password" value="" placeholder="Password" />
                                </div>

                                <button type="submit" className="submit">Register</button>
                                &nbsp;<Link to="/login">Already have account</Link>
                            </fieldset>
                        </form>

                    </div>

                    <Sidebar/>

                </div>
            </div>
        )
    }
}

export default Register;



resources/js/website/components/partials/Header.js

import React from 'react';
import {Link} from "react-router-dom";

class Header extends React.Component
{
    constructor(props)
    {
        super(props);
    }

    render()
    {
        return (
            <header id="top">

                <div className="row">

                    <div className="header-content twelve columns">

                        <h1 id="logo-text"><Link to="/">React Laravel Blog</Link></h1>
                        <p id="intro">Interactive website built with react and laravel</p>

                    </div>

                </div>

                <nav id="nav-wrap"><a id="toggle-btn" title="Menu" href="#">Menu</a>


                    <div className="row">

                        <ul id="nav" className="nav">
                            <li className="current"><Link to="/">Home</Link></li>
                            <li><a href="#">Category 1</a></li>
                            <li><a href="#">Category 2</a></li>
                            <li><a href="#">Category 3</a></li>
                            <li><a href="#">Category 4</a></li>
                        </ul>

                    </div>

                </nav>

            </header>
        )
    }
}

export default Header;

resources/js/website/components/partials/Footer.js

import React from 'react';
import {Link} from "react-router-dom";

class Footer extends React.Component
{
    constructor(props)
    {
        super(props);
    }

    render()
    {
        return (
            <footer>

                <div className="row">

                    <div className="six columns info">

                        <h3>About US</h3>

                        <p>Interactive website built with react and laravel
                        </p>
                    </div>

                    <div className="six columns">
                        <h3 className="social">Navigate</h3>

                        <ul className="navigate group">
                            <li><Link to="/">Home</Link></li>
                            <li><a href="#">Category 1</a></li>
                            <li><a href="#">Category 2</a></li>
                            <li><a href="#">Category 4</a></li>
                            <li><a href="#">Category 5</a></li>
                        </ul>
                    </div>

                </div>

            </footer>
        );
    }
}

export default Footer;

resources/js/website/components/partials/Sidebar.js

import React from 'react';
import {Link} from "react-router-dom";

class Sidebar extends React.Component
{
    constructor(props)
    {
        super(props);
    }

    render()
    {
        return (
            <div id="sidebar" className="four columns">
                <div className="widget widget_categories group">
                    <h3>Categories.</h3>
                    <ul>
                        <li><a href="#" title="">Wordpress</a> (2)</li>
                        <li><a href="#" title="">Ghost</a> (14)</li>
                        <li><a href="#" title="">Joomla</a> (5)</li>
                        <li><a href="#" title="">Drupal</a> (3)</li>
                        <li><a href="#" title="">Magento</a> (2)</li>
                        <li><a href="#" title="">Uncategorized</a> (9)</li>
                    </ul>
                </div>

                <div className="widget widget_tags">
                    <h3>Post Tags.</h3>

                    <div className="tagcloud group">
                        <a href="#">Corporate</a>
                        <a href="#">Onepage</a>
                        <a href="#">Agency</a>
                        <a href="#">Multipurpose</a>
                        <a href="#">Blog</a>
                        <a href="#">Landing Page</a>
                        <a href="#">Resume</a>
                    </div>

                </div>

            </div>
        );
    }
}

export default Sidebar;



resources/js/website/components/partials/Article.js

import React from "react";
import {Link} from "react-router-dom";

const Article = (props) => {

    return (
        <article className="entry">

            <header className="entry-header">

                <h2 className="entry-title">
                    <Link to="/p/1/title">Hey, We Love Open Sans!</Link>
                </h2>

                <div className="entry-meta">
                    <ul>
                        <li>July 12, 2014</li>
                        <span className="meta-sep">•</span>
                        <li><a href="#" title="" rel="category tag">Ghost</a></li>
                        <span className="meta-sep">•</span>
                        <li>John Doe</li>
                    </ul>
                </div>

            </header>

            <div className="entry-content-media">
                <div className="post-thumb">
                    <img src={process.env.MIX_APP_URL + 'assets/website/images/m-farmerboy.jpg'} />
                </div>
            </div>

            <div className="entry-content">
                <p>Duis ex ad cupidatat tempor Excepteur cillum cupidatat fugiat nostrud cupidatat dolor sunt sint sit nisi est eu exercitation incididunt adipisicing veniam velit id fugiat enim mollit amet anim veniam dolor dolor irure velit commodo cillum sit nulla ullamco magna amet magna cupidatat qui labore cillum sit in tempor veniam consequat non laborum adipisicing aliqua ea nisi sint ut quis proident ullamco ut dolore culpa occaecat ut laboris in sit minim cupidatat ut dolor voluptate enim veniam consequat occaecat fugiat in adipisicing in amet Ut nulla nisi non ut enim aliqua laborum mollit quis nostrud sed sed.</p>
            </div>

        </article>
    );
};

export default Article;

resources/js/website/components/partials/Comments.js

import React from 'react';

const Comments = (props) => {

    return (
            <ol className="commentlist">

                <li className="depth-1">

                    <div className="avatar">
                        <img className="avatar" src={process.env.MIX_APP_URL + 'assets/website/images/user-01.png'} alt="" width="50" height="50" />
                    </div>

                    <div className="comment-content">

                        <div className="comment-info">
                            <cite>Itachi Uchiha</cite>

                            <div className="comment-meta">
                                <time className="comment-time" datetime="2014-07-12T23:05">Jul 12, 2014 @ 23:05</time>
                            </div>
                        </div>

                        <div className="comment-text">
                            <p>Adhuc quaerendum est ne, vis ut harum tantas noluisse, id suas iisque mei. Nec te inani ponderum vulputate,
                                facilisi expetenda has et. Iudico dictas scriptorem an vim, ei alia mentitum est, ne has voluptua praesent.</p>
                        </div>

                    </div>

                </li>

                <li className="depth-1">

                    <div className="avatar">
                        <img className="avatar" src={process.env.MIX_APP_URL + 'assets/website/images/user-01.png'} alt="" width="50" height="50" />
                    </div>

                    <div className="comment-content">

                        <div className="comment-info">
                            <cite>Itachi Uchiha</cite>

                            <div className="comment-meta">
                                <time className="comment-time" datetime="2014-07-12T23:05">Jul 12, 2014 @ 23:05</time>
                            </div>
                        </div>

                        <div className="comment-text">
                            <p>Adhuc quaerendum est ne, vis ut harum tantas noluisse, id suas iisque mei. Nec te inani ponderum vulputate,
                                facilisi expetenda has et. Iudico dictas scriptorem an vim, ei alia mentitum est, ne has voluptua praesent.</p>
                        </div>

                    </div>

                </li>

                <li className="depth-1">

                    <div className="avatar">
                        <img className="avatar" src={process.env.MIX_APP_URL + 'assets/website/images/user-01.png'} alt="" width="50" height="50" />
                    </div>

                    <div className="comment-content">

                        <div className="comment-info">
                            <cite>Itachi Uchiha</cite>

                            <div className="comment-meta">
                                <time className="comment-time" datetime="2014-07-12T23:05">Jul 12, 2014 @ 23:05</time>
                            </div>
                        </div>

                        <div className="comment-text">
                            <p>Adhuc quaerendum est ne, vis ut harum tantas noluisse, id suas iisque mei. Nec te inani ponderum vulputate,
                                facilisi expetenda has et. Iudico dictas scriptorem an vim, ei alia mentitum est, ne has voluptua praesent.</p>
                        </div>

                    </div>

                </li>

            </ol>
    )
};

export default Comments;

resources/js/website/components/partials/CommentForm.js

import React from 'react';

class CommentForm extends React.Component
{
    constructor(props)
    {
        super(props);
    }

    render()
    {
        return (
            <div className="respond">

                <h3>Leave a Comment</h3>

                <form name="contactForm" id="contactForm" method="post" action="">
                    <fieldset>
                      
                        <div className="message group">
                            <textarea name="comment" id="cMessage" rows="10" cols="50"></textarea>
                        </div>

                        <button type="submit" className="submit">Submit</button>

                    </fieldset>
                </form>

            </div>
        );
    }
}

export default CommentForm;



After we created the components we will need to setup routes to navigate through page so create resources/js/website/Routes.js and add this code:

import React from 'react';
import { Route, Switch } from 'react-router-dom';
import Home from './components/pages/Home';
import Category from './components/pages/Category';
import Tag from './components/pages/Tag';
import Post from './components/pages/Post';
import Login from './components/pages/Login';
import Register from './components/pages/Register';

const Routes = (props) => {

    return (
        <Switch>
            <Route exact path="/" component={Home} />
            <Route path="/category/:id/:slug" component={Category} />
            <Route path="/tag/:id/:title" component={Tag} />
            <Route path="/p/:id/:slug" component={Post} />
            <Route path="/login" component={Login} />
            <Route path="/register" component={Register} />
        </Switch>
    )
};

export default Routes;

The above code contain the website routes as we did in the admin panel i added the routes in a separate component, let’s update App.js to setup react router.

resources/js/website/App.js

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import {HashRouter as Router} from "react-router-dom";
import Routes from './Routes';
import Header from './components/partials/Header';
import Footer from './components/partials/Footer';

export default class App extends Component {
    render() {
        return (
            <Router>
                <Header/>
                <Routes/>
                <Footer/>
            </Router>
        );
    }
}

if (document.getElementById('app')) {
    ReactDOM.render(<App />, document.getElementById('app'));
}

Now run

npm run dev

Navigate to the website and refresh it should display the the template we just added.

 

Continue to part12: Display Categories and Posts

 

0 0 vote
Article Rating
Share this: