Closed inkomomutane closed 2 years ago
Hey! Have you seen this part of the docs? https://github.com/ralphjsmit/laravel-seo#modifying-tags-before-they-are-rendered
yes. but i think is helpful.
SEOData::class
works for my case. but for now am running warnings like:PHP Warning: Attempt to read property "width" on null in C:\wamp64\www\mimovel\vendor\ralphjsmit\laravel-seo\src\Tags\TwitterCardTags.php on line 23
when i try to access this data.
Can you give a code example of how you are currently using this? So that I can take a good look at it and try to debug.
My Model.
`<?php
/**
namespace App\Models;
use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use RalphJSmit\Laravel\SEO\Support\HasSEO; use RalphJSmit\Laravel\SEO\Support\ImageMeta; use RalphJSmit\Laravel\SEO\Support\SEOData; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; use Spatie\Sluggable\HasSlug; use Spatie\Sluggable\SlugOptions; use Spatie\Tags\HasTags;
use function PHPSTORM_META\type;
/**
@package App\Models */ class Imovel extends Model implements HasMedia { use InteractsWithMedia,HasTags,HasSlug,HasSEO;
protected $table = 'imovels';
protected $casts = [ 'banheiros' => 'int', 'preco' => 'float', 'andares' => 'int', 'area' => 'float', 'quartos' => 'int', 'suites' => 'int', 'garagens' => 'int', 'piscinas' => 'int', 'views' => 'int', 'bairro_id' => 'int', 'condicao_id' => 'int', 'tipo_de_imovel_id' => 'int', 'status_id' => 'int', 'corretor_id' => 'int' ];
protected $dates = [ 'ano', 'published_at' ];
protected $fillable = [ 'titulo', 'descricao', 'slug', 'banheiros', 'preco', 'ano', 'andares', 'area', 'quartos', 'suites', 'garagens', 'piscinas', 'endereco', 'mapa', 'published_at', 'views', 'bairro_id', 'condicao_id', 'tipo_de_imovel_id', 'status_id', 'corretor_id' ];
public function bairro() { return $this->belongsTo(Bairro::class); }
public function condicao() { return $this->belongsTo(Condicao::class); }
public function status() { return $this->belongsTo(Status::class); }
public function tipo_de_imovel() { return $this->belongsTo(TipoDeImovel::class); }
public function corretor() { return $this->belongsTo(User::class, 'corretor_id'); }
public function comentarios() { return $this->hasMany(Comentario::class); }
public function ratings() { return $this->hasMany(Rating::class); }
/**
Get the options for generating the slug. */ public function getSlugOptions() : SlugOptions { return SlugOptions::create() ->generateSlugsFrom(['titulo']) ->saveSlugsTo('slug'); }
/**
public function registerMediaConversions(?Media $media = null): void { $this->addMediaConversion('thumb')->width('200')->nonQueued(); }
public function getDynamicSEOData(): SEOData { return new SEOData( title: $this->titulo, description: $this->descricao, author: $this->corretor->name, image: $this->hasMedia('posts') ? $this->getFirstMedia('posts')->getUrl() : null, type: 'article', published_time:$this->published_at, modified_time: $this->updated_at, imageMeta: $this->hasMedia('posts') ? new ImageMeta($this->getFirstMedia('posts')->getUrl() ): null, ); } } `
On tinker.
>>> seo()->for(Imovel::all()->last())
[!] Aliasing 'Imovel' to 'App\Models\Imovel' for this Tinker session.
<warning>PHP Warning: Attempt to read property "width" on null in C:\wamp64\www\mimovel\vendor\ralphjsmit\laravel-seo\src\Tags\TwitterCardTags.php on line 23</warning><warning>PHP Warning: Attempt to read property "height" on null in C:\wamp64\www\mimovel\vendor\ralphjsmit\laravel-seo\src\Tags\TwitterCardTags.php on line 23</warning>
<warning>PHP Warning: Attempt to read property "width" on null in C:\wamp64\www\mimovel\vendor\ralphjsmit\laravel-seo\src\Tags\TwitterCard\Summary.php on line 19</warning>
<warning>PHP Warning: Attempt to read property "width" on null in C:\wamp64\www\mimovel\vendor\ralphjsmit\laravel-seo\src\Tags\TwitterCardTags.php on line 27</warning><warning>PHP Warning: Attempt to read property "height" on null in C:\wamp64\www\mimovel\vendor\ralphjsmit\laravel-seo\src\Tags\TwitterCardTags.php on line 27</warning>
<warning>PHP Warning: Attempt to read property "width" on null in C:\wamp64\www\mimovel\vendor\ralphjsmit\laravel-seo\src\Tags\TwitterCard\SummaryLargeImage.php on line 19</warning>
=> RalphJSmit\Laravel\SEO\TagManager {#4006
+model: App\Models\Imovel {#4056
id: 10,
titulo: "Vupos matambo rero",
descricao: null,
banheiros: null,
preco: null,
ano: null,
andares: null,
area: null,
quartos: null,
suites: null,
garagens: null,
piscinas: null,
endereco: null,
mapa: null,
published_at: null,
views: 0,
created_at: "2022-05-30 13:25:30",
updated_at: "2022-05-30 13:25:30",
bairro_id: 2,
condicao_id: 1,
tipo_de_imovel_id: 2,
status_id: 2,
corretor_id: 1,
slug: "vupos-matambo-rero",
seo: RalphJSmit\Laravel\SEO\Models\SEO {#4047
id: 10,
model_type: "App\Models\Imovel",
model_id: 10,
description: null,
title: null,
image: null,
author: null,
created_at: "2022-05-30 13:25:30",
updated_at: "2022-05-30 13:25:30",
model: App\Models\Imovel {#4046
id: 10,
titulo: "Vupos matambo rero",
descricao: null,
banheiros: null,
preco: null,
ano: null,
andares: null,
area: null,
quartos: null,
suites: null,
garagens: null,
piscinas: null,
endereco: null,
mapa: null,
published_at: null,
views: 0,
created_at: "2022-05-30 13:25:30",
updated_at: "2022-05-30 13:25:30",
bairro_id: 2,
condicao_id: 1,
tipo_de_imovel_id: 2,
status_id: 2,
corretor_id: 1,
slug: "vupos-matambo-rero",
corretor: App\Models\User {#4728
id: 1,
name: "Test User",
email: "Admin@mimovel.com",
email_verified_at: "2022-05-21 14:28:36",
#password: "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi",
#remember_token: "gVJgVKFMn3MpsSzBBDoWDUFSfCvZnK9Cq4DNvkDx2Iz2tkF7XyXx4SnA9lpR",
created_at: "2022-05-21 14:28:36",
updated_at: "2022-05-21 14:28:36",
},
media: Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection {#4986
all: [
Spatie\MediaLibrary\MediaCollections\Models\Media {#4987
id: 45,
model_type: "App\Models\Imovel",
model_id: 10,
uuid: "74064c99-aecf-441e-a731-4ded2445214b",
collection_name: "posts",
name: "pexels-pixabay-209296",
file_name: "pexels-pixabay-209296.jpg",
mime_type: "image/jpeg",
disk: "posts",
conversions_disk: "posts",
size: 1624753,
manipulations: "[]",
custom_properties: "[]",
generated_conversions: "{"thumb": true}",
responsive_images: "{"media_library_original": {"urls": ["pexels-pixabay-209296___media_library_original_2845_1953.jpg", "pexels-pixabay-209296___media_library_original_2380_1634.jpg", "pexels-pixabay-209296___media_library_original_1991_1367.jpg", "pexels-pixabay-209296___media_library_original_1666_1144.jpg", "pexels-pixabay-209296___media_library_original_1394_957.jpg", "pexels-pixabay-209296___media_library_original_1166_800.jpg", "pexels-pixabay-209296___media_library_original_975_669.jpg", "pexels-pixabay-209296___media_library_original_816_560.jpg", "pexels-pixabay-209296___media_library_original_683_469.jpg", "pexels-pixabay-209296___media_library_original_571_392.jpg", "pexels-pixabay-209296___media_library_original_478_328.jpg", "pexels-pixabay-209296___media_library_original_400_275.jpg", "pexels-pixabay-209296___media_library_original_334_229.jpg", "pexels-pixabay-209296___media_library_original_280_192.jpg", "pexels-pixabay-209296___media_library_original_234_161.jpg"], "base64svg": "data:image/svg+xml;base64,PCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHhtbDpzcGFjZT0icHJlc2VydmUiIHg9IjAiCiB5PSIwIiB2aWV3Qm94PSIwIDAgMjg0NSAxOTUzIj4KCTxpbWFnZSB3aWR0aD0iMjg0NSIgaGVpZ2h0PSIxOTUzIiB4bGluazpocmVmPSJkYXRhOmltYWdlL2pwZWc7YmFzZTY0LC85ai80QUFRU2taSlJnQUJBUUVBWUFCZ0FBRC8vZ0E3UTFKRlFWUlBVam9nWjJRdGFuQmxaeUIyTVM0d0lDaDFjMmx1W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g4akp5dExUMU5YVzE5aloydUxqNU9YbTUranA2dkx6OVBYMjkvajUrdi9hQUF3REFRQUNFUU1SQUQ4QTkyWnRPdG0ydEt1ZnJYTjMvalMzMCsvOG9wKzYvdlYxV3Y4QXd1RTlpdjJXNXpJTythNEh4UDhBRFBVb3RLY0dUZXdIYnJYbzF1TDYxUjZTc2VCUTRYdzFQZlUzZE84ZTZUZFQrV1pWR1BlcnQ3NDE4UDJjVFBMZElvSHZYZ1gvQUFyUFY0NDNsV1dTTjkzdldSNHgrSE9zM21tUnFrMHU0OWNHcXA4VlY0TDM1WExyY05ZZWIvZHF4OWNEVXA0a3h2SnBzdDdKSkg4NTNEM29vcjhkbnVmYkl4TlF1VlZEKzdYOHE1SFZOVDJzUjVZSTlLS0t5azJYc2YvWiI+Cgk8L2ltYWdlPgo8L3N2Zz4="}}",
order_column: 1,
created_at: "2022-05-30 13:51:41",
updated_at: "2022-05-30 13:52:08",
+original_url: "http://www.mimovel.test/storage/posts/45/pexels-pixabay-209296.jpg",
+preview_url: "",
},
Spatie\MediaLibrary\MediaCollections\Models\Media {#4990
id: 46,
model_type: "App\Models\Imovel",
model_id: 10,
uuid: "578260f8-dada-4df1-94a5-3fdc69ba06ab",
collection_name: "posts",
name: "pexels-david-mcbee-1546168",
file_name: "pexels-david-mcbee-1546168.jpg",
mime_type: "image/jpeg",
disk: "posts",
conversions_disk: "posts",
size: 1007546,
manipulations: "[]",
custom_properties: "[]",
generated_conversions: "{"thumb": true}",
responsive_images: "[]",
order_column: 2,
created_at: "2022-05-30 13:51:42",
updated_at: "2022-05-30 13:51:44",
+original_url: "http://www.mimovel.test/storage/posts/46/pexels-david-mcbee-1546168.jpg",
+preview_url: "",
},
Spatie\MediaLibrary\MediaCollections\Models\Media {#4991
id: 47,
model_type: "App\Models\Imovel",
model_id: 10,
uuid: "3bfda063-55b6-45a9-9755-baf17f258c57",
collection_name: "posts",
name: "pexels-pixabay-259962",
file_name: "pexels-pixabay-259962.jpg",
mime_type: "image/jpeg",
disk: "posts",
conversions_disk: "posts",
size: 1671192,
manipulations: "[]",
custom_properties: "[]",
generated_conversions: "{"thumb": true}",
responsive_images: "[]",
order_column: 3,
created_at: "2022-05-30 13:51:44",
updated_at: "2022-05-30 13:51:45",
+original_url: "http://www.mimovel.test/storage/posts/47/pexels-pixabay-259962.jpg",
+preview_url: "",
},
Spatie\MediaLibrary\MediaCollections\Models\Media {#4992
id: 48,
model_type: "App\Models\Imovel",
model_id: 10,
uuid: "2c0cf3f6-3d49-4da9-8104-c3b3079dbbcb",
collection_name: "posts",
name: "pexels-mark-mccammon-2724749",
file_name: "pexels-mark-mccammon-2724749.jpg",
mime_type: "image/jpeg",
disk: "posts",
conversions_disk: "posts",
size: 1845299,
manipulations: "[]",
custom_properties: "[]",
generated_conversions: "[]",
responsive_images: "[]",
order_column: 4,
created_at: "2022-05-30 13:51:45",
updated_at: "2022-05-30 13:51:45",
+original_url: "http://www.mimovel.test/storage/posts/48/pexels-mark-mccammon-2724749.jpg",
+preview_url: "",
},
],
},
},
},
},
+tags: RalphJSmit\Laravel\SEO\TagCollection {#4980
all: [
RalphJSmit\Laravel\SEO\Tags\RobotsTags {#4049
all: [
RalphJSmit\Laravel\SEO\Support\MetaTag {#5002
+tag: "meta",
+attributesPipeline: [],
+name: "robots",
+content: "max-snippet:-1,max-image-preview:large,max-video-preview:-1",
},
RalphJSmit\Laravel\SEO\Support\LinkTag {#5012
+tag: "link",
+attributesPipeline: [],
+rel: "canonical",
+href: "http://www.mimovel.test",
},
],
},
RalphJSmit\Laravel\SEO\Support\MetaTag {#5013
+tag: "meta",
+attributesPipeline: [],
+name: "author",
+content: "Test User",
},
RalphJSmit\Laravel\SEO\Tags\TitleTag {#5014
+tag: "title",
+attributesPipeline: [],
+inner: "Vupos matambo rero",
},
RalphJSmit\Laravel\SEO\Support\MetaTag {#5015
+tag: "meta",
+attributesPipeline: [],
+name: "image",
+content: "http://www.mimovel.test/storage/posts/45/pexels-pixabay-209296.jpg",
},
RalphJSmit\Laravel\SEO\Tags\OpenGraphTags {#5016
all: [
RalphJSmit\Laravel\SEO\Support\OpenGraphTag {#5017
+tag: "meta",
+attributesPipeline: [
Closure(Collection $collection) {#5018 …4},
],
+name: "title",
+content: "Vupos matambo rero",
},
RalphJSmit\Laravel\SEO\Support\OpenGraphTag {#5019
+tag: "meta",
+attributesPipeline: [
Closure(Collection $collection) {#5020 …4},
],
+name: "locale",
+content: "pt_br",
},
RalphJSmit\Laravel\SEO\Support\OpenGraphTag {#5021
+tag: "meta",
+attributesPipeline: [
Closure(Collection $collection) {#5022 …4},
],
+name: "image",
+content: "http://www.mimovel.test/storage/posts/45/pexels-pixabay-209296.jpg",
},
RalphJSmit\Laravel\SEO\Support\OpenGraphTag {#5023
+tag: "meta",
+attributesPipeline: [
Closure(Collection $collection) {#5024 …4},
],
+name: "url",
+content: "http://www.mimovel.test",
},
RalphJSmit\Laravel\SEO\Support\OpenGraphTag {#5025
+tag: "meta",
+attributesPipeline: [
Closure(Collection $collection) {#5026 …4},
],
+name: "type",
+content: "article",
},
RalphJSmit\Laravel\SEO\Support\MetaTag {#5027
+tag: "meta",
+attributesPipeline: [],
+name: "article:published_time",
+content: "2022-05-30T13:25:30+00:00",
},
RalphJSmit\Laravel\SEO\Support\MetaTag {#5028
+tag: "meta",
+attributesPipeline: [],
+name: "article:modified_time",
+content: "2022-05-30T13:25:30+00:00",
},
],
},
RalphJSmit\Laravel\SEO\Tags\TwitterCardTags {#5029
all: [
RalphJSmit\Laravel\SEO\Tags\TwitterCard\Summary {#5030
all: [],
},
RalphJSmit\Laravel\SEO\Tags\TwitterCard\SummaryLargeImage {#5031
all: [],
},
RalphJSmit\Laravel\SEO\Support\TwitterCardTag {#5032
+tag: "meta",
+attributesPipeline: [
Closure(Collection $collection) {#5034 …4},
],
+name: "title",
+content: "Vupos matambo rero",
},
],
},
],
},
}
>>>
Thanks for reporting! This is fixed in version 1.0.2. 👍
Hello @ralphjsmit. Thanks for you package How can I add costume meta-tags like og:url , og:type etc storing this data on database. like Costume Proprieties of laravel-Media-library.