Skip to content

Instantly share code, notes, and snippets.

@MrAtiebatie
Last active October 4, 2019 08:15
Show Gist options
  • Save MrAtiebatie/9e0a22f6cf132d6f17837d5ee28e1d49 to your computer and use it in GitHub Desktop.
Save MrAtiebatie/9e0a22f6cf132d6f17837d5ee28e1d49 to your computer and use it in GitHub Desktop.
<?php
namespace App\Repositories;
use App\Models\Product;
use MrAtiebatie\Repository;
use Illuminate\Database\Eloquent\Model;
/**
* Product repository
*/
class ProductRepository extends Model
{
use Repository;
/**
* The model being queried.
*
* @var \Illuminate\Database\Eloquent\Model
*/
protected $model;
/**
* Constructor
*/
public function __construct()
{
$this->model = app(Product::class);
}
/**
* Find published products by SKU
* @param {int} $sku
* @return {Product}
*/
public function findBySku(int $sku): Product {
return this->whereIsPublished(1)
->whereSku($sku)
->first();
}
}
@AliN11
Copy link

AliN11 commented Oct 4, 2019

@felipefrancisco

Ahh came here to notice that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment