我是laravel的新手,我在标题中描述了异常。我知道我需要"使用App \ Model_Name;"。请帮忙! 这是Model Class
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
}
这是Controller类
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Product;
class ProductsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return Post::all();
return view('products.index');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
答案 0 :(得分:0)
你应该使用PostController而不是ProductController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Product;
class PostController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return Post::all();
return view('products.index');
}
答案 1 :(得分:0)
<强>把强> 使用App \ Post;
正好在之下 使用Illuminate \ Http \ Request;
控制器中的
答案 2 :(得分:0)
更改此 使用Illuminate \ Http \ Request; 使用App \ Product;
进入 使用Illuminate \ Http \ Request; 使用App \ Post;