ralphjsmit / laravel-seo

A package to handle the SEO in any Laravel application, big or small.
https://ralphjsmit.com/laravel-seo-package
MIT License
648 stars 52 forks source link

Class "App\Http\Controllers\SEOData" not found #31

Closed salmanmichsan closed 1 year ago

salmanmichsan commented 1 year ago

in my controller : $seo = new SEOData(

        title: $room->title,

        description: $room->description,

    );

    // return $seo;

    return view('web.pages.roomdetail',compact('room','ruangan','offers','seo'));
poonasor commented 1 year ago

having the same issue here in my controller

ralphjsmit commented 1 year ago

@poonasor You need to import it:

use RalphJSmit\Laravel\SEO\Support\SEOData;
poonasor commented 1 year ago

Thanks @ralphjsmit I've tired that before but still getting Undefined variable $SEOData

ralphjsmit commented 1 year ago

@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.

poonasor commented 1 year ago

@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

ralphjsmit commented 1 year ago

@poonasor Ok, what's your Blade code?

poonasor commented 1 year ago

in my layout.blade.php in views/components is

{!! seo($SEOData) !!}

poonasor commented 1 year ago

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..

ralphjsmit commented 1 year ago

@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.

poonasor commented 1 year ago

in my test.blade.php file i have: <x-layout :SEOData="$SEOData">

and still getting: Undefined variable $SEOData

ralphjsmit commented 1 year ago

OK, that looks good, and how does your layout.blade.php look like?

poonasor commented 1 year ago
  @if (isset($SEOData))
    {!! seo($SEOData) !!}
  @else
    {!! seo() !!}
  @endif
dilab commented 1 year ago

So what was the issue?

poonasor commented 6 months ago

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',
            ),
        ]);