0

I am trying different methods to resolve it for 5 hours but can't may any method work.

This is my web.php file:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', 'LaptopController@show');

This is Laptop.php(Model):

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Laptop extends Model
{
    //
}

This is LaptopController.php (Controller):

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use app\Laptop;
class LaptopController extends Controller
{
    public function show(){
        $laptop=Laptop::all();
        echo $laptop->name;
    }
}
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Ahsan Asif
  • 123
  • 3
  • 9

1 Answers1

0

Inside the controller you are using

use app\Laptop;

but instead it should be

use App\Laptop;

In addition to this there is the problem that you are trying to access name of a Collection: if you want just the first one you should do Laptop::first()

Alberto Sinigaglia
  • 12,097
  • 2
  • 20
  • 48