lundi 19 mars 2018

Class 'Model name' not found in Larvel

This is my controller but so that i can download excel. The locations of the controller and the model are both the same I already checked it but still there's an error and it says that "Class "App\Item" Not Found".

namespace Vanguard\Http\Controllers\Web;
use Input;
use App\Item;
use DB;
use Excel;
use Illuminate\Http\Request;
use Vanguard\Http\Controllers\Controller;
use Cache;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class MaatwebsiteDemoController extends Controller
{
    public function importExport()
    {
        return view('importExport');
    }
    public function downloadExcel()
    {
        $data = Item::get()->toArray();
        return Excel::create('itsolutionstuff_example', function($excel) use ($data) {
            $excel->sheet('mySheet', function($sheet) use ($data)
            {
                $sheet->fromArray($data);
            });
        })->download($type);
    }
    public function importExcel()
    {
        if(Input::hasFile('import_file')){
            $path = Input::file('import_file')->getRealPath();
            $data = Excel::load($path, function($reader){
            })->get();
            if(!empty($insert)){
                foreach ($data as $key => $value) {
                    $insert[] = ['title' => $value->title, 'description' => $value->description];
                }
            if(!empty($insert)){
                DB::table('items')->insert($insert);
                dd('Insert Record succesfully');
            }
            }
        }
        return back();
    }
}

Then this is how my Model is.

<?php

namespace Vanguard\App;

use Illuminate\Database\Eloquent\Model;

class Item extends Model
{
    public $fillable = ['title','description'];
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire