tobros91
tobros91

Reputation: 668

Laravel use public_path in model?

I am trying to use the public_path helper to define some standard folders in my model, but i get the following error. Is it not possible to use helper functions in the models? In the controller everything works fine.

class Varaimage extends \Eloquent {

public $sizes = array(
                array('folder'=>'/large/', 'width'=>'1000'),
                array('folder'=>'/thumb/', 'width'=>'150')
);

public $folder         = public_path().'/images/varor/';

exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'syntax error, unexpected '(', expecting ',' or ';'' in /var/www/html/kollavaran/app/models/Varaimage.php:13

Upvotes: 0

Views: 714

Answers (2)

Marwelln
Marwelln

Reputation: 29413

PHP doesn't support setting properties with a function. What you have to do is to use your __construct method.

public $folder;

public function __construct() {
    $this->folder = public_path() . '/images/varor/';
}

http://www.php.net/manual/en/language.oop5.properties.php

They (properties) are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

Upvotes: 2

itachi
itachi

Reputation: 6393

because php doesn't allow it (because it is not implemented). however you can do this.

public $folder;

public function __construct()
{
    $this->folder = public_path().'/images/varor/';

}

not tested though.

Upvotes: 3

Related Questions