S
S
Stanislav Pochepko2016-01-09 19:26:50
Laravel
Stanislav Pochepko, 2016-01-09 19:26:50

How to make a converter to file in Eloquent?

Good evening community. Is it possible to make an attribute converter from a model $this->imageto a file (similar to the date converter in Carbon)? So that when reading the attribute, the file object would be returned immediately, and not the path to it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2016-01-09
@DJZT

https://laravel.com/docs/5.1/eloquent-mutators#acc...

public function getImageAttribute($value)
{
    return new \SplFileInfo(/*path to file*/)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question