Skip to content

Instantly share code, notes, and snippets.

@rizkhal
Last active February 22, 2020 06:08
Show Gist options
  • Save rizkhal/5a6150085d47df03e5afc6fc58b7ccd9 to your computer and use it in GitHub Desktop.
Save rizkhal/5a6150085d47df03e5afc6fc58b7ccd9 to your computer and use it in GitHub Desktop.
<?php
namespace App\Repositories\Eloquent;
use App\Repositories\Eloquent\Entities\Post;
use App\Repositories\PostRepositoryInterface as PostInterface;
class PostEloquent implements PostInterface
{
protected $model;
public function __construct(Post $model)
{
$this->model = $model;
}
public function all()
{
return $this->model->all();
}
public function take(int $limit = 10)
{
return $this->all()->take($limit);
}
public function paginate(int $limit = 5)
{
return $this->model->paginate($limit);
}
public function save(array $request)
{
if(is_array($request)) {
return $this->model->create($request);
}
return false;
}
public function findBySlug(string $slug)
{
return $this->model->where('slug', $slug)->first();
}
public function update(string $slug, array $request)
{
$post = $this->findBySlug($slug);
if(!empty($post)) {
return $post->update($request);
}
return false;
}
public function find(string $slug)
{
//
}
public function delete(string $slug)
{
$post = $this->findBySlug($slug);
if(!empty($post)) {
$post->delete();
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment