Last active
September 11, 2019 12:36
-
-
Save MrAtiebatie/ad998e3738db2a63849c80027cdfb650 to your computer and use it in GitHub Desktop.
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
<?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