Fateh Alrabeai
Fateh Alrabeai

Reputation: 730

How to get the full path of an image in laravel API?

I want to get the path of an image using mutators or helper function for example this is My request :

 "placeType": {
        "id": 1,
        "name": "Kenya Wyman",
        "image_name": "1574668070.png",
        "status": 1,
}
}

I want it to appear like this :

 "placeType": {
        "id": 1,
        "name": "Kenya Wyman",
        "image_name": "www.mydomain.com/photos/1574668070.png",
        "status": 1,
}
}

Upvotes: 3

Views: 4502

Answers (3)

VIKAS KATARIYA
VIKAS KATARIYA

Reputation: 6005

Try This

$user->image_name = url('public/Your path ' . $user->image_name);

OR

In your Model Add this

public function getImageNameAttribute($value)
{

        return public_path($value);
}

Upvotes: 3

Yogesh Sharma
Yogesh Sharma

Reputation: 61

Try to use this code :

asset('photos/1574668070.png');

Upvotes: 1

user10678889
user10678889

Reputation:

Try to use this code :

$data->image_name = URL::to('/') . '/public/imageFolder/' . $placeType->image_name;

Upvotes: 0

Related Questions