gpt4 book ai didi

php - 我需要将我的数据从数据库加载到我的电子商务索引页面。管理部分完全没问题。但是我的用户出错了

转载 作者:行者123 更新时间:2023-12-03 11:22:49 26 4
gpt4 key购买 nike

我创建了两个资源 Controller ,一个用于管理员,另一个用于用户。
我得到的错误是,

Illuminate\Contracts\Container\BindingResolutionException Target class[App\Http\Controllers\ProductsController] does not exist.


我的代码有什么问题?
这是我的 Admin\ProductsController.php
<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Product;
use App\Category;

class ProductsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}


public function index()
{
$arr['products'] = Product::all();
return view('admin.products.index')->with($arr);
}




public function create()
{
return view('admin.products.create');
}


public function store(Request $request, Product $product)
{

if($request->prod_image_path->getClientOriginalName())
{
$ext =$request->prod_image_path->getClientOriginalName();
$file = date('YmdHis').rand(1,99999).'.'.$ext;
$request->prod_image_path->storeAs('public/admin',$file);
}else{
$file ='';
}

$product-> prod_name = $request-> prod_name;
$product-> prod_meta_title = $request-> prod_meta_title;
$product-> prod_description = $request-> prod_description;
$product-> prod_category = $request-> prod_category;
$product-> prod_price = $request-> prod_price;
$product-> prod_discount = $request-> prod_discount;
$product-> prod_image_path = $file;

$product->save();
return redirect()->route('admin.products.index');

}


public function show($id)
{
// $product = Product::find($id);
// return view ('user.show',['product'=>$product]);
}


public function edit(Product $product)
{
$arr['product'] = $product;
return view('admin.products.edit')->with($arr);

}


public function update(Request $request, Product $product)
{
if($request->prod_image_path->getClientOriginalName())
{
$ext =$request->prod_image_path->getClientOriginalName();
$file = date('YmdHis').rand(1,99999).'.'.$ext;
$request->prod_image_path->storeAs('public/admin',$file);
}else{
$file ='';
}
$product-> prod_name = $request-> prod_name;
$product-> prod_meta_title = $request-> prod_meta_title;
$product-> prod_description = $request-> prod_description;
$product-> prod_category = $request-> prod_category;
$product-> prod_price = $request-> prod_price;
$product-> prod_discount = $request-> prod_discount;
$product-> prod_image_path = $file;
$product->save();
return redirect()->route('admin.products.index');
}


public function destroy($id)
{
Product:: destroy($id);
return redirect()->route('admin.products.index');
}
}
这是用户的 ProductsController.php
<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Product;

class ProdutsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}

public function index()
{
$products = Product::get();
return view ('index')->with(compact('products'));

}


public function create()
{

}

public function store(Request $request, Product $product)
{


}


public function show($id)
{
//
}



public function edit(Product $product)
{

}


public function update(Request $request, Product $product)
{

}


public function destroy($id)
{

}
}
这是我的路线。
网页.php
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/admin/index', 'ProductsController@index')->name('list_products');
Route::get('/admin', 'HomeController@test')->name('admin');
Route::resource('/admin/products', 'Admin\ProductsController', ['as'=>'admin']);
Route::resource('/index', 'ProductsController');
这是我的 index.blade.php
@foreach($products as $p)    
<a href="../shop/product-categories-7-column-full-width.html" class="d-block py-2 text-center">
<img class="img-fluid mb-1 max-width-100-sm" src="{{ asset('assets/img/300X300/img6.jpg')}}" alt="Image Description">
<h6 class="font-size-14 mb-0 atext font-weight-semi-bold">{{ $p ['prod_name'] }}</h6>
<h6 class="font-size-14 mb-0 atext font-weight-semi-bold">{{ $p ['prod_price'] }}</h6>
</a>
</li>
@endforeach

最佳答案

我认为您的用户 ProductController Controller 名称有误。
您的实际类(class)名称是:ProdutsController但 Laravel 正在寻找 ProductsController

关于php - 我需要将我的数据从数据库加载到我的电子商务索引页面。管理部分完全没问题。但是我的用户出错了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63166671/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com