我正在建立我的第一个电子商务网站,但我不知道如何在管理面板中创建和查看客户的订单。我尝试遵循不同的教程,但对我而言不起作用。而且由于我是laravel的新手,所以不确定在哪里添加行。
这是我的 OrdersController
class OrdersController extends Controller
{
public function index () {
$session_id = Session::get('session_id');
$cart_datas = Cart_model::where('session_id', $session_id)->get();
$total_price = 0;
foreach ($cart_datas as $cart_data) {
$total_price += $cart_data->price * $cart_data->quantity;
}
$shipping_address = DB::table('delivery_address')->where('users_id', Auth::id())->first();
return view('checkout.review_order', compact('shipping_address', 'cart_datas', 'total_price'));
}
public function order (Request $request) {
$input_data = $request->all();
$payment_method = $input_data['payment_method'];
Orders_model::create($input_data);
if ( $payment_method == "COD" ) {
return redirect('/cod');
} else {
return redirect('/paypal');
}
}
public function cod () {
$user_order = Orders_model::where('users_id', Auth::id())->first();
return view('payment.cod', compact('user_order'));
}
public function paypal (Request $request) {
$who_buying = Orders_model::where('users_id', Auth::id())->first();
return view('payment.paypal', compact('who_buying'));
}
public function show($id) {}
}
这是 web.php
/* Admin Location */
Auth::routes(['register'=>false]);
Route::get('/home', 'HomeController@index')->name('home');
Route::group(['prefix'=>'admin','middleware'=>['auth','admin']],function () {
Route::get('/', 'AdminController@index')->name('admin_home');
/// Setting Area
Route::get('/settings', 'AdminController@settings');
Route::get('/check-pwd', 'AdminController@chkPassword');
Route::post('/update-pwd', 'AdminController@updatAdminPwd');
/// Category Area
Route::resource('/category', 'CategoryController');
Route::get('delete-category/{id}', 'CategoryController@destroy');
Route::get('/check_category_name', 'CategoryController@checkCateName');
/// Products Area
Route::resource('/product', 'ProductsController');
Route::get('delete-product/{id}', 'ProductsController@destroy');
Route::get('delete-image/{id}', 'ProductsController@deleteImage');
/// Product Attribute
Route::resource('/product_attr', 'ProductAtrrController');
Route::get('delete-attribute/{id}', 'ProductAtrrController@deleteAttr');
/// Product Images Gallery
Route::resource('/image-gallery', 'ImagesController');
Route::get('delete-imageGallery/{id}', 'ImagesController@destroy');
/// ///////// Coupons Area //////////
Route::resource('/coupon', 'CouponController');
Route::get('delete-coupon/{id}', 'CouponController@destroy');
//Admin orders Routes
Route::resource('/view-Orders', 'OrdersController@index');
});
这是我的管理工具栏
<!--sidebar-menu-->
<div id="sidebar"><a href="{{url('/admin')}}" class="visible-phone"><i class="icon icon-home"></i> Dashboard</a>
<ul>
<li{{$menu_active==1? ' class=active':''}}><a href="{{url('/admin')}}"><i class="icon icon-home"></i> <span>Dashboard</span></a> </li>
<li class="submenu {{$menu_active==2? ' active':''}}"> <a href="#"><i class="icon icon-th-list"></i> <span>Categories</span></a>
<ul>
<li><a href="{{url('/admin/category/create')}}">Add New Category</a></li>
<li><a href="{{route('category.index')}}">List Categories</a></li>
</ul>
</li>
<li class="submenu {{$menu_active==3? ' active':''}}"> <a href="#"><i class="icon icon-th-list"></i> <span>Products</span></a>
<ul>
<li><a href="{{url('/admin/product/create')}}">Add New Products</a></li>
<li><a href="{{route('product.index')}}">List Products</a></li>
</ul>
</li>
<li class="submenu {{$menu_active==3? ' active':''}}"> <a href="#"><i class="icon icon-th-list"></i> <span>Orders</span></a>
<ul>
<li><a href="{{url('/admin/view-orders')}}">list orders</a></li>
</ul>
</li>
</ul>
</div>
<!--sidebar-menu-->
答案 0 :(得分:0)
在开始一个大项目之前,您应该了解更多。这是来自数据库的简单read
操作。但是我给你一个简单的例子
管理员侧边栏
<li class="submenu {{$menu_active==3? ' active':''}}">
<a href="#"><i class="icon icon-th-list"></i> <span>Orders</span></a>
<ul>
<li><a href="{{route('admin.view-orders')}}">list orders</a></li>
</ul>
</li>
路由文件
Route::get('view-orders', 'OrdersController@listOrders')->name('admin.view-orders');
控制器
public function listOrders() {
$orders = Orders_model::all(); //here you can order as you wish
return view('orders.index',compact('orders'));
}
最后是视图文件
<table>
<thead>
<tr>
<th>Sl#</th>
<th>Attributes</th>
............
</tr>
</thead>
<tbody>
@foreach($orders as $order)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $order->attribute }}</td>
......................
</tr>
@endforeach
</tbody>
</table>
希望您了解逻辑。