Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image won't load #1275

Closed
MyhedinZika opened this issue Oct 18, 2018 · 7 comments
Closed

image won't load #1275

MyhedinZika opened this issue Oct 18, 2018 · 7 comments

Comments

@MyhedinZika
Copy link

Hi there, I've been trying to show the image on view, but I can't seem to get it to work

I get this on console log

GET http://uw-test.test/storage/1/AddStock2.PNG 404 (Not Found)

I've been trying lots of stuff to show the image, but I can't seem to make it work, clearly I must be missing something. Any help is great

This is my controller
$products = Product::select('products.*')
->keywords(request('search'))
->join('categories', 'categories.id', '=', 'products.category_id')
->category(request('category_id'))
->with('media')
->paginate(config('fi.resultsPerPage'));

This is dd of products
LengthAwarePaginator {#698
#total: 5
#lastPage: 1
#items: Collection {#712
#items: array:5 [▼
0 => Product {#703 ▶}
1 => Product {#705 ▶}
2 => Product {#702 ▶}
3 => Product {#701 ▶}
4 => Product {#700
#guarded: array:1 [▶]
#connection: "mysql"
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:26 [▶]
#original: array:26 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: array:1 [▼
"media" => Collection {#691
#items: array:1 [▼
0 => Media {#697
#guarded: []
#casts: array:3 [▶]
#connection: "mysql"
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:15 [▼
"id" => 1
"model_type" => "FI\Modules\Products\Models\Product"
"model_id" => 5
"collection_name" => "products"
"name" => "AddStock2"
"file_name" => "AddStock2.PNG"
"mime_type" => "image/png"
"disk" => "public"
"size" => 64212
"manipulations" => "[]"
"custom_properties" => "{"custom_headers": []}"
"responsive_images" => "[]"
"order_column" => 1
"created_at" => "2018-10-18 20:41:48"
"updated_at" => "2018-10-18 20:41:48"
]
#original: array:15 [▶]
#changes: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
}
]
}
]
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
+mediaConversions: []
+mediaCollections: []
#deletePreservingMedia: false
#unAttachedMediaLibraryItems: []
}
]
}
#perPage: "15"
#currentPage: 1
#path: "http://uw-blb.test/products"
#query: []
#fragment: null
#pageName: "page"
}

My model is like this
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;

class Product extends Model implements HasMedia
{
use Sortable;
use HasMediaTrait;

public function registerMediaCollections()
{
$this->addMediaCollection('products');

}

This is my ProductCreateController
if ($request->has('attachments')) {
foreach ($request->attachments as $key => $imagen) {
try {
$product->addMedia($request->attachments[$key])->toMediaCollection('products');
} catch (DiskDoesNotExist $e) {
} catch (FileDoesNotExist $e) {
} catch (FileIsTooBig $e) {
}
}
}

@Dmarthaller
Copy link

Hi I see two different server domain names in your comments are you pulling your images from the same server or is there a problem with your generated path names?

@MyhedinZika
Copy link
Author

Hmm nah apparently that's not the issue, was thinking that might have been the issue, but nah its not apparently.

I'm on http://uw-blb.test/products

Its the same path
products:770 GET http://uw-blb.test/storage/2/AllOrders.PNG 404 (Not Found)
products:731 GET http://uw-blb.test/storage/1/AddStock2.PNG 404 (Not Found)
products:848 GET http://uw-blb.test/storage/4/Ballina.PNG 404 (Not Found)
products:809 GET http://uw-blb.test/storage/3/createVendor.PNG 404 (Not Found)

@Dmarthaller
Copy link

Dmarthaller commented Oct 20, 2018 via email

@MyhedinZika
Copy link
Author

Yes I have tried that, but unfortunately thats not the problem

The "public/storage" directory already exists.

@Dmarthaller
Copy link

Dmarthaller commented Oct 20, 2018 via email

@bxmas13
Copy link

bxmas13 commented Nov 5, 2018

@MyhedinZika I had a similar situation happen on my site. It wasn't until I read the comment by @Dmarthaller that I realized I might have an issue with my storage link.
It turns out that when I moved my site to a different directory the symlink didn't transfer correctly. It ended up making a copy of the 'storage' directory instead of remaining a symlink.
I even ran php artisan storage:link and it came up with 'The "public/storage" directory already exists.'

I decided to double check that the public/storage directory did in fact exist. That's when I noticed it wasn't a symlink but an actual directory. After making a quick backup of my site I removed the 'public/storage' directory and ran php artisan storage:link again. Once the function completed all my images started loading as expected.

@cuevven
Copy link

cuevven commented Dec 5, 2018

If you use homestead, you need to use the php artisan storage:link command in vm.

  1. unlink storage in your host OS
  2. vagrant ssh
  3. php artisan storage:link

You can get more details from laravel/framework#15439

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants