怎么写才可以让这段代码更加优雅
麻烦大家请看以下代码
我想让代码变得更加优雅
代码附上:
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018\11\2 0002
* Time: 13:02
*/
namespace App\Http\Controllers\Boot;
use App\Http\Requests\StoreArticle;
use App\Models\Article;
use App\Models\ArticleCategory;
use Illuminate\Http\Request;
use Mockery\Exception;
class ArticleController extends CommonController
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index($recover = false, $type = null, $order = null)
{
//default article list
$articles = Article:: with('category')->orderBy('created_at','desc')->paginate(10);
//if is recover list
if ($recover == true){
//count attribute and order
if ($type !== null && $order !== null){
$articles = Article::onlyTrashed()->orderBy($type,$order)->paginate(10);
}else{
$articles = Article::onlyTrashed()->orderBy('created_at','desc')->paginate(10);
}
}else{
//count attribute and order
if ($type !== null && $order !== null){
$articles = Article::with('category')->orderBy($type,$order)->paginate(10);
}
}
return view('boot.article.index', [
'articles' => $articles,
'recover' => $recover,
'order' => $order,
'type' => $type,
]);
}
}
多写各路大佬随意回复
推荐文章: