Closed salmanmichsan closed 1 year ago
having the same issue here in my controller
@poonasor You need to import it:
use RalphJSmit\Laravel\SEO\Support\SEOData;
Thanks @ralphjsmit I've tired that before but still getting
Undefined variable $SEOData
@poonasor "undefined variable" is a different error than the class not found error.
In your code, you called it $seo
instead of $SEOData
, so you need to replace the $SEOData
variable name in your Blade file as well with $seo
.
@ralphjsmit that wasn't my code, heres what I have
Route::get('/test', function () { return view('test', [ 'SEOData' => new SEOData( title: 'Awesome News - My Project', description: 'Lorem Ipsum', ), ]); });
appreciate it
@poonasor Ok, what's your Blade code?
in my layout.blade.php in views/components is
{!! seo($SEOData) !!}
So for the $SEOData to work in /views/components/layout.blade.php
I needed to add in AppServiceProvider.php in the boot() function
// Share the SEOData variable with all views
View::share('SEOData', new SEOData(
title: 'Awesome News - My Project',
description: 'Lorem Ipsum',
));
however, the title and description is the same for all pages..
@poonasor How does your test.blade.php
look like? You need to pass the $SEOData variable from the test.blade.php
file into your layout.blade.php
file.
in my test.blade.php file i have:
<x-layout :SEOData="$SEOData">
and still getting:
Undefined variable $SEOData
OK, that looks good, and how does your layout.blade.php
look like?
@if (isset($SEOData))
{!! seo($SEOData) !!}
@else
{!! seo() !!}
@endif
So what was the issue?
So what was the issue?
its only pulling the default title and description, and won't pull the title and description from the controller
in my layout.blade.php i have:
@if (isset($SEOData))
{!! seo($SEOData) !!}
@else
{!! seo() !!}
@endif
im getting:
Undefined variable $SEOData
in my controller:
use RalphJSmit\Laravel\SEO\Support\SEOData;
return view('home', [
'SEOData' => new SEOData(
title: 'Awesome News - My Project',
description: 'Lorem Ipsum',
),
]);
in my controller : $seo = new SEOData(