0% found this document useful (0 votes)
28 views

How To Add Blog Url

The document provides instructions on how to create a blog listing page in a Laravel application. The steps include adding a route, copying and renaming a view file, updating the view code, and creating a controller method to return the view with blog post data.

Uploaded by

xloypts708
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

How To Add Blog Url

The document provides instructions on how to create a blog listing page in a Laravel application. The steps include adding a route, copying and renaming a view file, updating the view code, and creating a controller method to return the view with blog post data.

Uploaded by

xloypts708
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

1. Go to “routes/web.

php”
Edit the file and add this code,

Route::get('/blog', 'blogList')→name('blogs.list');

2. Go to “resources/views”, then do “Copy file” for file “blog-show.blade.php”.

3. Rename the copied file as “blog-list.blade.php”.

4. Edit the copied file and use this code.

<!-- START -->


@extends('layouts.frontend')

@section('css')
<!--<link href="{{URL::asset('plugins/awselect/awselect.min.css')}}" rel="stylesheet" />-->
<!-- <link href="{{URL::asset('plugins/slick/slick.css')}}" rel="stylesheet" />-->
<!--<link href="{{URL::asset('plugins/slick/slick-theme.css')}}" rel="stylesheet" />-->
<!-- <link href="{{URL::asset('plugins/aos/aos.css')}}" rel="stylesheet" />-->
<!-- <link href="{{URL::asset('plugins/animatedheadline/jquery.animatedheadline.css')}}"
rel="stylesheet" />-->
@endsection

@section('menu')
<div class="container secondary-navbar">
<div class="row">

<nav class="navbar navbar-expand-lg navbar-light w-100" id="navbar-responsive">


<a class="navbar-brand" href="{{ url('/') }}"><img id="brand-img"
src="{{ URL::asset('img/brand/logo.png') }}" alt=""></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-
target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle
navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse section-links" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link scroll active" href="{{ url('/') }}/#main-
wrapper">{{ __('Home') }} <span class="sr-only">(current)</span></a>
</li>
@if (config('frontend.features_section') == 'on')
<li class="nav-item">
<a class="nav-link scroll" href="{{ url('/') }}/#features-
wrapper">{{ __('Features') }}</a>
</li>
@endif
@if (config('frontend.pricing_section') == 'on')
<li class="nav-item">
<a class="nav-link scroll" href="{{ url('/') }}/#prices-
wrapper">{{ __('Pricing') }}</a>
</li>
@endif
@if (config('frontend.faq_section') == 'on')
<li class="nav-item">
<a class="nav-link scroll" href="{{ url('/') }}/#faq-wrapper">{{ __('FAQs') }}</a>
</li>
@endif
@if (config('frontend.blogs_section') == 'on')
<li class="nav-item">
<a class="nav-link scroll" href="{{ url('/') }}/#blog-wrapper">{{ __('Blogs')
}}</a>
</li>
@endif
</ul>

@if (Route::has('login'))
<div id="login-buttons">
@auth
<a href="{{ route('user.templates') }}" class="action-button dashboard-button pl-5
pr-5">{{ __('Dashboard') }}</a>
@else
<a href="{{ route('login') }}" class="" id="login-button">{{ __('Sign In') }}</a>
@if (config('settings.registration') == 'enabled')
@if (Route::has('register'))
<a href="{{ route('register') }}" class="ml-2 action-button register-button pl-5
pr-5">{{ __('Sign Up') }}</a>
@endif
@endif
@endauth
</div>
@endif
</div>
</nav>

</div>
</div>
@endsection

@section('content')
@if (config('frontend.blogs_section') == 'on')
<section id="blog-wrapper">

<div class="container pt-9 text-center">

<!-- SECTION TITLE -->


<div class="row mb-7">
<div class="title">
<p class="m-2">{{ __('Stay up to Date') }}</p>
<h3>{{ __('Our Latest') }} <span>{{ __('Blogs') }}</span></h3>
</div>
</div> <!-- END SECTION TITLE -->

</div> <!-- END CONTAINER -->

<div class="container">

@if (count($articles) > 0)

<!-- BLOGS -->


<div class="row" id="blogs">
@foreach ( $articles as $blog )
<div class="blog mb-8" data-aos="zoom-in" data-aos-delay="100" data-aos-
once="true" data-aos-duration="400">
<div class="blog-box">
<div class="blog-img">
<a href="{{ route('blogs.show', $blog->url) }}"><img
src="{{ URL::asset($blog->image) }}" alt="Blog Image"></a>
<span>{{ $blog->created_by }}</span>
</div>
<div class="blog-info mt-0">
<h6 class="blog-date text-left mt-1 mb-4">{{ date('F j, Y', strtotime($blog-
>created_at)) }}</h6>
<h5 class="blog-title fs-20 text-left mb-4"><a href="{{ route('blogs.show',
$blog->url) }}">{{ __($blog->title) }}</a></h5>
<h6><a href="{{ route('blogs.show', $blog->url) }}">{{ __('Read
More') }}</a> <i class="fa-solid fa-chevrons-right"></i></h6>
</div>
</div>
</div>
@endforeach
</div>

{{ $articles->links() }}
@else
<div class="row text-center">
<div class="col-sm-12 mt-6 mb-6">
<h6 class="fs-12 font-weight-bold text-center">{{ __('No blog articles were
published yet') }}</h6>
</div>
</div>
@endif

</div> <!-- END CONTAINER -->

</section> <!-- END SECTION BLOGS -->


@endif
@endsection

@section('js')
<!-- Awselect JS -->
<script src="{{URL::asset('plugins/awselect/awselect.min.js')}}"></script>
<script src="{{URL::asset('js/awselect.js')}}"></script>
<script src="{{URL::asset('js/minimize.js')}}"></script>
@endsection
<!-- END -->

5. Save the file.

6. Go to “app/Http/Controllers/HomeController.php” and edit it.


Add this code to that file,

// START
public function blogList()
{
$articles = Blog::paginate(2); // Change 10 to the number of articles per page you desire

$information_rows = ['js', 'css'];


$information = [];
$settings = Setting::all();

foreach ($settings as $row) {


if (in_array($row['name'], $information_rows)) {
$information[$row['name']] = $row['value'];
}
}

$information['author'] = '';
$information['title'] = 'Our Blogs';
$information['keywords'] = '';
$information['description'] = '';

return view('blog-list', compact('information', 'articles'));


}
// END

You might also like