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