#175
Автор: Stack Developers
Загружено: 2021-07-08
Просмотров: 834
Описание:
In Part-175 of Advance E-commerce series, we will continue working on CMS Pages. In this video, we will display cms pages in admin panel with option of making them active/inactive.
1) Create CmsController :-
First of all, we will create CmsController under app/Http/Controllers/Admin folder.
Create CmsController by running below artisan command :-
php artisan make:controller Admin/CmsController
2) Create Model :-
Create CmsPage model by running below artisan command :-
php artisan make:model CmsPage
3) Create Route :-
Create GET route in web.php file in admin middleware group prefixed with admin and having namespace Admin for displaying cms pages in admin panel :-
// CMS Pages
Route::get('cms-pages','CmsController@cmspages');
4) Create cmspages function :-
Now create cmspages function in CmsController to write query to display all the cms pages in admin panel and return to cms_pages.blade.php file that we will create under /resources/views/admin/pages/ folder.
5) Include CmsPage model :-
Include CmsPage model at top of CmsController.
use App\CmsPage;
6) Create cms_pages.blade.php file :-
Now create cms_pages.blade.php file under /resources/views/admin/pages/ folder in which we will display cms pages within foreach loop.
7) Update admin_layout.blade.php file :-
Now update admin_layout.blade.php file to add DataTable jQuery script for cms pages to display the cms pages in datatable.
Now we will work on active/inactive status for the cms pages.
Active status will have 1 value and Inactive status will have 0 value in cms_pages table.
8) Update cms_pages.blade.php file :-
Add id, class and page_id attributes for Active and Inactive status for cms_pages at cms_pages.blade.php file that are required to update the status with jquery and ajax.
9) Update admin_script.js file :-
Add updateCmsPageStatus jquery function in admin_script.js file in which we will pass status and page_id that we will return to ajax via admin/update-cms-page-status route.
10) Create Route :-
Now we will create below Post route in admin middleware group in web.php file for updating status that we pass via ajax in last step.
Route::post('update-cms-page-status','CmsController@updateCmsPageStatus');
11) Update VerifyCsrfToken.php :-
Add route "admin/update-cms-page-status" in VerifyCsrfToken.php file so that CSRF token mismatch error won't come.
12) Create updateCmsPageStatus :-
Now we will create updateCmsPageStatus in CmsController to update the status of cms page in cms_pages table and return back the updated status to ajax via json.
13) Update admin_script.js file :-
Update admin_script.js file again to get the status and page id in ajax response and update status in cms_pages.blade.php file.
14) Update admin_sidebar.blade.php file :-
Update Admin sidebar to add CMS Pages tab in which we will display "View CMS Pages" link and will highlight it when CMS Pages module selected.
15) Update cmspages function :-
Update cmspages function once again to add session variable for pages with value cmspages and add "Use Session" at top of CmsController.
Session::put('page','cmspages');
Now you can check in video; we able to display cms pages with active/inactive status.
Thanks for watching :)
Join this channel to get complete code/support:
/ @stackdevelopers
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: