Add meta tags to laravel page

Are you extending another template that uses all these sections? They won't work on their own, they need to populate a placeholder in another template.

It should be something like:

<!-- layouts.master -->
<html>
    <head>
        <title>App Name - @yield('title')</title>
        <meta name="description" content="@yield('description')">
        <meta name="keywords" content="@yield('keywords')">
        <!-- etc -->
    </head>
    <body>
        ...
    </body>
</html>

And then your template should extend the other template.

@extends('layouts.master')
@section('title')
{{trans('strings.About')}}
@stop
@section('description', 'Share text and photos with your friends and have fun')
@section('keywords', 'sharing, sharing text, text, sharing photo, photo,')
@section('robots', 'index, follow')
@section('revisit-after', 'content="3 days')

At least, that is how I read their documentation: https://laravel.com/docs/5.2/blade


You can create only one section with all these important tags that I have mentioned below. And @yield this section in app layout <head> section of HTML code.

@section('meta_tags')
    @if($obj)
        <title>{{$obj->title}} - {{env('SITE_URL', 'Site Name')}}</title>
        <meta name='description' itemprop='description' content='{{$obj->description}}' />
        <?php $tags = implode(',', $obj->tags); ?>
        <meta name='keywords' content='{{$tags}}' />
        <meta property='article:published_time' content='{{$obj->created_at}}' />
        <meta property='article:section' content='event' />

        <meta property="og:description" content="{{$obj->description}}" />
        <meta property="og:title" content="{{$obj->title}}" />
        <meta property="og:url" content="{{url()->current()}}" />
        <meta property="og:type" content="article" />
        <meta property="og:locale" content="en-us" />
        <meta property="og:locale:alternate" content="en-us" />
        <meta property="og:site_name" content="{{env('SITE_URL', 'Site Name')}}" />
        @foreach($obj->images as $image)
            <meta property="og:image" content="{{$image->url}}" />
        @endforeach
        <meta property="og:image:url" content="{{obj->image}}" />
        <meta property="og:image:size" content="300" />

        <meta name="twitter:card" content="summary" />
        <meta name="twitter:title" content="{{$obj->title}}" />
        <meta name="twitter:site" content="@BrnBhaskar" />
    @endif
@endsection

I have better one! Create Include file like this 'views/widgets/meta.blade.php'

<meta name="title" content="{{ $meta->meta_title }}"/>
<meta name="keywords" content="{{ $meta->meta_keywords }}"/>
<meta name="description" content="{{ $meta->meta_description }}"/>
<meta name="robots" content="index,follow"/> 
<meta name="revisit-after" content="7 days">
<meta name="coverage" content="Worldwide">
<meta name="distribution" content="Global">
<meta name="title" content="{{ $meta->meta_title }}">
<meta name="author" content="{{ setting('site.title')}}">
<meta name="url" content="{{ request()->fullUrl() }}">
@isset($metaArray->og_image)
<meta name="og_image" content="{{ asset('storage/' . $meta->og_image)  }}"/>
<meta name="og_secureImage" content="{{ asset('storage/' . $meta->og_image)  }}"/>
<meta name="og_imageAlt" content="{{ $meta->og_imageAlt }}"/>
<meta name="og_imageType" content="{{ $meta->og_imageType }}"/>
@endisset
<meta name="rating" content="General">
<meta property=”og:title” content="{{ $meta->meta_title }}"/>
<meta property="og:description" content="{{ $meta->meta_description }}"/>
<meta property=”og:type” content=”{{ $meta->og_type }}”/>
<meta property="og:locale" content="en_us" />
<meta property="og:sitename" content="{{ setting('site.title') }}" />
<meta property="og:url" content="{{ request()->fullUrl() }}"/>
<meta name="twitter:card" content="summary"/>
<meta name="twitter:site" content="{{ setting('site.twitter_site') }}"/>
<meta name="twitter:creator" content="{{ setting('site.twitter_creator') }}"/>

And then whenever you want to include meta just pass array through the include

@include('widgets.meta',$meta)

And also you can replace setting() with $metaArray. I'm using Voyager.