[Seri] - Website đồng hồ - Tạo Controller category và thư mục chưa category

Bài này mình sẽ tạo controller xử lý cho Category và thư mục chứa form, danh sách category

Nội dung bài này mình sẽ tạo controller xử lý, đồng thời cũng tạo thư mục category nằm trong thư mục admin chứa các file như

  • index.blade.php dùng để hiển thị danh sách danh mục
  • create.blade.php dùng để hiển thị view thêm mới danh mục
  • update.blade.php dùng để hiện thị view edit danh mục 

Tạo AdminCategoryController

Các bạn run lệnh sau 

php artisan make:controller Admin/AdminCategoryController

Sau khi chạy xong thì bạn vào app/Http/Controller/Admin/ sẽ thấy một controller được tạo là AdminCategoryController

nội dung file đó như sau

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

class AdminCategoryController extends AdminController
{
    public function index()
    {
        return view('admin.category.index');
    }
}

Tạo view 

Trong thư mục resource/admin các bạn tạo cho mình thư mục category và 3 file như mình đã liệt kê ở trên 

Và nội dung file index.blade.php sẽ là 

Và ở file app_master_admin.blade.php mình cũng đã gắn lại link menu cho category các bạn chú ý sử theo nhé.

Route

Các bạn mở file route_admin.php lên và thay nội dung này vào nhé


    
    Route::group(['prefix' => 'api-admin','namespace' => 'Admin'], function() {
        Route::get('/', function () {
             return view('admin.index');
        });

        Route::group(['prefix' => 'category'], function(){
            Route::get('','AdminCategoryController@index')->name('admin.category.index');
        });
    });

Link video

Để lại comment của bạn nếu gặp khó khăn

Bài viết liên quan