This commit is contained in:
merdan 2021-05-11 17:39:09 +05:00
parent d5de974669
commit 65177db6e3
3 changed files with 17 additions and 10 deletions

View File

@ -2,7 +2,8 @@
use Cms\Classes\Controller;
use BackendMenu;
use DB;
use Config;
use Illuminate\Http\Request;
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
use Illuminate\Support\Facades\Validator;
@ -21,15 +22,16 @@ class postsController extends Controller
}
public function index(){
$data = $this->Post::with(['categories'])->listFrontEnd([
$path = Config::get('app.cdn');
$data = $this->Post::with(['categories:id,name'])->listFrontEnd([
'page' => input('page'),
'sort' => input('sort')??'published_at',
'sort' => input('sort')??'published_at desc',
'perPage' => input('count'),
'search' => trim(input('search')),
'category' => input('category'),
'date' => input('date'),
'published' => true
'published' => true,
'select' => ['id','title','published_at',DB::raw("IF(featured_image<>'',concat('$path',image),image) as main_image")]
]);
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
}

View File

@ -264,14 +264,15 @@ class Post extends Model
extract(array_merge([
'page' => 1,
'perPage' => 30,
'sort' => 'created_at',
'sort' => 'published_at',
'categories' => null,
'exceptCategories' => null,
'category' => null,
'search' => '',
'date' => '',
'date' => '',
'published' => true,
'exceptPost' => null
'exceptPost' => null,
'select' => null
], $options));
$searchableFields = ['title', 'slug', 'excerpt'];
@ -375,6 +376,10 @@ class Post extends Model
});
}
if($select){
$query->select($select);
}
return $query->paginate($perPage, $page);
}

View File

@ -26,8 +26,8 @@ secondaryTabs:
fields:
content:
tab: rainlab.blog::lang.post.tab_edit
# type: RainLab\Blog\FormWidgets\BlogMarkdown
type: richeditor
type: RainLab\Blog\FormWidgets\BlogMarkdown
# type: richeditor
cssClass: field-slim blog-post-preview
stretch: true
mode: split