1

I am new to laravel and I got exception descripted in title. I know that I need to "use App\Model_Name;". Please Help! This is Model Class

<?php

 namespace App;

 use Illuminate\Database\Eloquent\Model;

 class Product extends Model
 {

 }

This is Controller class

<?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
  • I think you mean Product::all() not Post:all() Commented Aug 6, 2017 at 17:04
  • Thanks, man! It helped. In the example video author worked with Posts(blog) and i thought Post is the method, not the name Commented Aug 6, 2017 at 17:10

3 Answers 3

5

put use App\Post;

just below use Illuminate\Http\Request;

in your controller class

Sign up to request clarification or add additional context in comments.

Comments

1

you should use PostController and not 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');
  }

2 Comments

But ProductController is one I created for working with model. Is the name make difference?
If you want access to a controllerAction for PostController be sure you have a PostController .. otherwise you get the error you show in question ..
1

Change this use Illuminate\Http\Request; use App\Product;

into use Illuminate\Http\Request; use App\Post;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.