Skip to content

Instantly share code, notes, and snippets.

View Mombuyish's full-sized avatar
Never stop progressing.

Yish Mombuyish

Never stop progressing.
View GitHub Profile
$ php artisan ide-helper:models Post
<?php
Route::resource('articles', 'ArticlesController');
<?php
Route::get('articles/user/{user}', 'Articles\showByUser');
<?php
class PostRepository
{
protected $model;
public function __construct(Post $model)
{
$this->model = $model;
}
public function getActiveAll()
<?php
class Post extends Model
{
public function scopeActive($query)
{
return $query->where('status', 1);
}
}
<?php
class Post extends Model
{
/**
* Create a new Eloquent Collection instance.
*
* @param array $models
* @return \App\Collection
*/
<?php
class PostRepository
{
protected $model;
public function __construct(Post $model)
{
$this->model = $model;
}
public function getAll()
<?php
//PostService
class PostService
{
protected $postRepository;
public function __construct(PostRepository $postRepository)
{
$this->postRepository = $postRepository;
}
//get Active data
@foreach ($posts->active() as $post)
//.....
@endforeach
//get deactivate data
@foreach ($posts->deactivate() as $post)
//.....
@endforeach
<?php
//PostRepository 不需要做任何更動。
//PostService
class PostService
{
protected $postRepository;
public function __construct(PostRepository $postRepository)
{
$this->postRepository = $postRepository;