-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdd47be
commit ab7f0e4
Showing
15 changed files
with
143 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,58 @@ | ||
<?php | ||
|
||
namespace CwsDigital\TwillMetadata\Traits; | ||
|
||
use Artesaos\SEOTools\Facades\SEOTools; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
trait SetsMetadata { | ||
|
||
public function setMetadata(Model $describable) { | ||
trait SetsMetadata | ||
{ | ||
public function setMetadata(Model $describable) | ||
{ | ||
$metadata = $describable->metadata; | ||
|
||
if(!$metadata) return; // Prevent errors if model has no attached metadata | ||
if (! $metadata) { | ||
return; | ||
} // Prevent errors if model has no attached metadata | ||
|
||
SEOTools::setTitle($metadata->field('title')); | ||
|
||
if( $metadata->field('description') ) { | ||
if ($metadata->field('description')) { | ||
SEOTools::setDescription($metadata->field('description')); | ||
} | ||
|
||
SEOTools::opengraph()->setTitle($metadata->field('og_title')); | ||
|
||
if($metadata->field('og_description')) { | ||
if ($metadata->field('og_description')) { | ||
SEOTools::opengraph()->setDescription($metadata->field('og_description')); | ||
} | ||
|
||
SEOTools::opengraph()->addProperty('type', $metadata->field('og_type')); | ||
|
||
if($metadata->field('og_image')) { | ||
if ($metadata->field('og_image')) { | ||
SEOTools::opengraph()->addImage($metadata->field('og_image')); | ||
} | ||
|
||
SEOTools::opengraph()->setUrl(request()->url()); | ||
|
||
if($metadata->field('canonical_url')) { | ||
if ($metadata->field('canonical_url')) { | ||
SEOTools::metatags()->setCanonical($metadata->field('canonical_url')); | ||
} | ||
|
||
$noindex = $metadata->field('noindex'); | ||
$nofollow = $metadata->field('nofollow'); | ||
|
||
if( $noindex || $nofollow ) { | ||
if( $noindex && $nofollow ) { | ||
SEOTools::metatags()->setRobots('noindex, nofollow'); | ||
if ($noindex || $nofollow) { | ||
if ($noindex && $nofollow) { | ||
SEOTools::metatags()->setRobots('noindex, nofollow'); | ||
} else { | ||
if($noindex) { | ||
if ($noindex) { | ||
SEOTools::metatags()->setRobots('noindex'); | ||
} | ||
if($nofollow) { | ||
if ($nofollow) { | ||
SEOTools::metatags()->setRobots('nofollow'); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.