Chức năng Quản lý sản phẩm, các bạn làm tương tự như chức năng Back-end. Quản lý chuyên mục mình đã làm trước đó
Tải lên nhiều là một trong những tính năng được sử dụng khá nhiều trong trang web ứng dụng. Phần này mình sẽ hướng dẫn xây dựng chức năng upload ảnh cho sản phẩm
Trong bài viết này, mình sẽ sử dụng
php artisan make:controller Admin\AdminProductController
4. Nó là một thư viện đơn giản để tạo chức năng tải tệp lên theo định dạng "Kéo và thả". Khác với thư viện javascript khác, Dropzone hỗ trợ nhiều tùy chọn khác nhauXem trước. Chức năng upload nhiều hình ảnh cho sản phẩm.
Vâng. Bây giờ chúng ta sẽ bắt đầu
Bước 1. Thêm tuyến đường
Route::resource['product', 'AdminProductController'];
Route::post['uploadImg', 'AdminUploadController@postImages'];
Bước 2. Thêm phương pháp điều khiển
php artisan make:controller Admin\AdminProductController
File dung
php artisan make:controller Admin\AdminProductController
5class AdminProductController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index[]
{
$this->data['title'] = 'List products';
$productsInfo = DB::table['products']
->orderBy['id', 'desc']
->paginate[10];
$this->data['listProduct'] = $productsInfo;
return view['admin.product.index', $this->data];
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create[]
{
$this->data['title'] = 'Add new product';
$listCate = DB::table['categories']->orderBy['id', 'desc']->get[];
$this->data['listCate'] = $listCate;
return view['admin.product.create', $this->data];
}
php artisan make:controller Admin\AdminUploadController
Bộ điều khiển này để xử lý tải lên, xóa hình ảnh = ajax
Nội dung
php artisan make:controller Admin\AdminProductController
6