Home Articles

找不到类'App\Http\Controllers\Post'

Asked
Viewed 318 times
1

我是laravel的新手,我在 Headers 中有例外描述 . 我知道我需要“使用App \ Model_Name;” . 请帮忙!这是模型类

<?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)
{
    //
}

}

2 Answers

  • 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');
      }
    
  • 0

    put 使用App \ Post;

    just below 使用Illuminate \ Http \ Request;

    在你的控制器中

Related