Web Student
Web Student

Reputation: 735

Laravel get instance in a model

First please be gentle i am a beginner and im only coding for practise.

I try to pass an instance to the model but i always get this error

Argument 1 passed to Store::__construct() must be an instance of Illuminate\Filesystem\Filesystem, none given

my model

<?php

use Illuminate\Filesystem\Filesystem as File;

class Store extends Eloquent
{
    public $timestamps = false;

    public function __construct(File $file)
    {
        $this->file = $file;
    }

}

Could please somebody tell me what i am doing wrong?

thank you

EDIT

I just used simply like this in my Controller

public function index()
    {
        $store = new Store;
        return View::make('store', $store);
    }

Upvotes: 1

Views: 6521

Answers (1)

SamV
SamV

Reputation: 7586

The File class is one of Laravels Facades, which means you do not need to pass it into your models construct.

You can access it from anywhere in Laravel using File::someMethod(). If you use namespaces then you have to access via the root namespace \File::someMethod().

Within your store view you can access the File facade directly with the aforementioned method.

Take a look at the documentation on the file system here http://laravel.com/api/class-Illuminate.Filesystem.Filesystem.html

So you can use File::copy() without having to instantiate a class as it is called from a static method.

Upvotes: 3

Related Questions