@yoba Have you declared the variable $newsPost, and if so, what does it contain? Could you maybe provide a bit more code, it would be help debug the problem.
Apr 21, 2023
2
Level 1
Get 404 while retrieving image
Image successfully uploaded to the storage storage/app/public/news/image.png.
But while try to get it on a page is nothing appear. Try to go via link is 404. How to get image
Page with image
<img class="profile-pic"
src="{{ asset(\Illuminate\Support\Facades\Storage::url($newsPost->image)) }}">
Controller
public function store(StoreNewsRequest $request)
{
$data = $request->validated();
if ($request->file('image')) {
$file = $request->file('image')->store('news', 'public');
$data['image'] = $file;
}
$user = User::find($request->user()->id);
$post = $user->news()->create(
$data
);
return Redirect::route('news.show', $post->id);
}
Env
FILESYSTEM_DISK=public
$newPost variable contains
object(App\Models\News)#1289 (29) { ["connection":protected]=> string(5) "mysql" ["table":protected]=> string(4) "news" ["primaryKey":protected]=> string(2) "id" ["keyType":protected]=> string(3) "int" ["incrementing"]=> bool(true) ["with":protected]=> array(0) { } ["withCount":protected]=> array(0) { } ["preventsLazyLoading"]=> bool(false) ["perPage":protected]=> int(15) ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) ["escapeWhenCastingToString":protected]=> bool(false) ["attributes":protected]=> array(8) { ["id"]=> int(45) ["title"]=> string(5) "Test9" ["description"]=> string(103) "aagae;iueqrp9q3ypegsp48yfsvvbds eugeoferigy w[f29r [wf 498 eg0[3ygw0 yew[0ety3g0efgdiu[;b ]h0h';cv sjkg" ["image"]=> string(49) "news/Fa6UJF2ZWEXHKBFNWX0T0wQRisEvbCGAJbBYkXul.png" ["image_link"]=> string(16) "https://test.com" ["created_at"]=> string(19) "2023-04-21 10:55:32" ["updated_at"]=> string(19) "2023-04-21 10:55:32" ["user_id"]=> int(1) } ["original":protected]=> array(8) { ["id"]=> int(45) ["title"]=> string(5) "Test9" ["description"]=> string(103) "aagae;iueqrp9q3ypegsp48yfsvvbds eugeoferigy w[f29r [wf 498 eg0[3ygw0 yew[0ety3g0efgdiu[;b ]h0h';cv sjkg" ["image"]=> string(49) "news/Fa6UJF2ZWEXHKBFNWX0T0wQRisEvbCGAJbBYkXul.png" ["image_link"]=> string(16) "https://test.com" ["created_at"]=> string(19) "2023-04-21 10:55:32" ["updated_at"]=> string(19) "2023-04-21 10:55:32" ["user_id"]=> int(1) } ["changes":protected]=> array(0) { } ["casts":protected]=> array(0) { } ["classCastCache":protected]=> array(0) { } ["attributeCastCache":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["appends":protected]=> array(0) { } ["dispatchesEvents":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["relations":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["timestamps"]=> bool(true) ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["fillable":protected]=> array(4) { [0]=> string(5) "title" [1]=> string(11) "description" [2]=> string(5) "image" [3]=> string(10) "image_link" } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } }
P.S. storage:link was execute already
Please or to participate in this conversation.