Reputation: 17
Hello i came across to this tutorial
http://www.dunebook.com/learn-how-to-import-data-from-csv-using-eloquent-in-laravel/
I create what is on tutorial
Migration
so i create a model
Scifi.php
class Scifi extends Eloquent {
protected $table = 'scifi';
}
on my routes.php
Route::get('csv', function()
{
if (($handle = fopen(public_path() .. '/scifi.csv','r')) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ',')) !==FALSE)
{
$scifi = new Scifi();
$scifi->character = $data[0];
$scifi->movie = $data[1];
$scifi->save();
}
fclose($handle);
}
return Scifi::all();
});
But when i access it
localhost/laravelcsv/public/csv
I get this error
FatalErrorException in routes.php line 14:Class 'Scifi' not found
Upvotes: 0
Views: 6232
Reputation: 1
class is not found an error in Laravel :
to solve this problem you just add use App\Scifi
on top
directory/className
Upvotes: 0
Reputation: 9439
You are not referring the name space for your model file in your controller. So please refer your model.
use App\Scifi;
If you are using Scifi
model in App\Model
folder,
use App\Model\Scifi;
Upvotes: 0
Reputation: 142
You need a namespace for Scifi class:
use App\Scifi; statement in routes.php:
Upvotes: 1