for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Larafolio\Models\ContentTraits;
use Larafolio\Models\Link;
trait HasLinks
{
/**
* Get a model from a relationship by model name.
*
* @param string $relationship Name of relationship.
* @param string $name Name of model to get.
* @return \Illuminate\Database\Eloquent\Model|null
*/
abstract protected function getFromRelationshipByName($relationship, $name);
* A resource has many text blocks.
* @return MorphMany
public function links()
return $this->morphMany(Link::class, 'resource');
}
* Return true if project has links.
* @return bool
public function hasLinks()
return !$this->links->isEmpty();
links
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
* Get link by name, if exists.
* @param string $name Name of link to get.
* @return Larafolio\Models\Link|null
public function link($name)
return $this->getFromRelationshipByName('links', $name);
* Get link url.
* @param string $name Name of link.
* @return string|null
public function linkUrl($name)
if (!$link = $this->link($name)) {
return;
return $link->url();
* Get link text.
public function linkText($name)
return $link->text();
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: