L
L
lolrofl012020-01-27 23:57:02
Laravel
lolrofl01, 2020-01-27 23:57:02

How to get a value from a database bypassing a mutator?

Good afternoon.
I have images for posts in the database. Images are of the form name.png. Thanks to mutators, I determined that every time a post image is called, the full path is automatically added to it. And now there is a need to delete the image knowing the ID of the post. By id, I pull out the post, but the image, as expected, contains the full path. Is there any additional option in Laravel that would indicate that this time the image should be pulled from the database bypassing the mutator? Those. so that it is pulled out in the format in which it lies in the database: name.png?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Shapoval, 2020-01-28
@lolrofl01

Instead of (for example)
$post->image;
Try
$post->getOriginal('image');

K
Konstantin B., 2020-01-28
@Kostik_1993

$model->attributes['image'];
// Но правильнее всетаки сделать отдельный мутатор для полного пути.
$model->getImageUrlAttribute();

D
Dmitry, 2020-01-28
@Compolomus

https://www.php.net/manual/ru/function.basename.php as an option

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question