Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SEO on Laravel 5.4 [closed]

I am implementing a website for generating analytics for various institutes in the USA. I now need to implement SEO on my website. I have edited all the URL's to have them SEO friendly. Now my question is, how to find the keywords,meta tags for my laravel website and how to include them in my website. On my home page ? or any where else ?

like image 413
A.n1014 Avatar asked Dec 18 '22 08:12

A.n1014


1 Answers

Create a layout.blade.php and @yield the section named title and meta. When the user requests the page, it will pass through controller from which you can fetch the Title and meta description tag from your post_meta table or some table in which you store your Meta description.

I am working on one CMS based on Laravel and I am doing same. To make it easy for you to understand, here is the simple example!

Example Route.php (Your User Friendly URLs)

Route::get("page/{page_id}","PageController@show");


Example Controller Function

public function show($page_id)
{
    // Fetching Meta Tag Content from Table and Passing it to View
    $page_meta = Page::getMeta($page_id);

    return view('pages.show')->with('meta_description',$page_meta);
}


Example Layout.blade.php (Your Layout file)

<html>
    <head>
        @yield('title_and_meta')
    </head>
    <body>
        @yield('body_content')
    </body>
</html>


Example Page view (Your view file that will be shown to user!)

@extends('your_layout')

@section('title_and_meta')
    <title>Your Page title</title>
    <meta name="description" content="{{ $meta_description }}" />
@endsection

@section('body_content')
    // Content here!
@endsection

Surely, you can use the Variables Passed from Controller in the views! You can pass the Array Containing Title, Meta Description, Meta Author, Meta Keywords (Deprecated) and more Page meta Stuff and show it in the view!

This is how you make your Laravel Project SEO Friendly. My Content Management System is not yet Ready otherwise I can give you the URL of my GitHub Project from which you can understand it better!

Hope this helps! Let me know if you have any more Questions!

like image 127
p01ymath Avatar answered Jan 05 '23 16:01

p01ymath