Skip to content

Instantly share code, notes, and snippets.

@MrAtiebatie
Last active September 11, 2019 12:36
Show Gist options
  • Save MrAtiebatie/ad998e3738db2a63849c80027cdfb650 to your computer and use it in GitHub Desktop.
Save MrAtiebatie/ad998e3738db2a63849c80027cdfb650 to your computer and use it in GitHub Desktop.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'products';
/**
* Find published product by name
* @param string $name
* @return Product
*/
public function findByName(string $name): Product
{
return $this->whereName($name)
->whereIsPublished(1)
->first();
}
/**
* Say we want to concat the name and a category name
* @return string
*/
public function concatName(): string
{
return $this->attributes['name'] . ' - ' . $this->attributes['category_name'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment