I'm loading multiple images and sometimes it works fine and another hangs, other times it doesn't take certain images and redirects me to page 404. I would like if you can give me a hand. I appreciate very much any intention.
I am using Livewire as follows:
<input wire:model="imagenes" type="file" name="imagenes" class="form-control-file" multiple>
Once the images are selected, it goes through the validator:
$this->validate([
'imagenes.*' => 'image|max:2048',
]);
And to save the images I am using the following methodology
foreach ($this->imagenes as $pathGaleria) {
$imgUrl = $pathGaleria->store('imagenesPropiedades');
$img = imgPropiedades::create([
'url' => $imgUrl,
'property_id' => $this->propiedadId
]);
}
On the filesystem:
'imagenesPropiedades' => [
'driver' => 'local',
'root' => public_path(),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
I get this error in console
Can you give me a suggestion to improve this load please.
The problem was that since I use livewire in real time, I had not contemplated the enctype = "multipart / form-data" tag, and I also had to expand the max_upload server spaces. Thanks a lot
Related
I need the deploy my laravel project to the web. With this introduction But the hosting provider is Doesn't allow me to use a symbolic link(symlink), I called customer service, and told me blocked for security reasons.
So, since I do not use symbolic links, there are big problems in uploading images and deploying them.
Is there a way to do deployment my app?
Change your disk configurations in the config/filesystems.php to read and write to public folder via public_path() function.
If you're deploying over a shared host, you probably have another folder like public_html as your public folder which is not included in your source. Try to link to the public_html using dots ../../public_html/
'public' => [
'driver' => 'local',
// 'root' => storage_path('app/public'),
'root' => public_path(),
'url' => env('APP_URL'),
'visibility' => 'public',
],
'photos' => [
'driver' => 'local',
'root' => public_path('photos'),
'url' => env('APP_URL') . '/photos',
'visibility' => 'public',
],
Another way is just create something like symlink using php, example you can create a route like below:
Route::get(
'/storage/{file}',
function ($file) {
$filepath = "../storage/app/public/".$file;
header("Cache-Control: public");
header("Content-Type: ".mime_content_type($filepath));
header('Content-Length: '.filesize($filepath));
readfile($filepath);
die();
}
);
Maybe not best practice, but it will solve your problem. It's will do same as symlink.
i want to rewrite my URLs from
/view?id=100
to
/view/100-article-title
But the site already has several thousand search pages. As far as I know, such a change can be bad for SEO. Is there a way to keep the old URLs working when switching to the new routing.
*I am creating links as follows:
Url::to(['view', 'id' => $item->id])
Is it possible to create links further through ID?
you can create getLink() function on your model and use it on. Then, when function runs you can check id if id <= 100 then return Url::to(['view', 'id' => $item->id]) else return Url::to(['view', 'id' => $item->id, 'slug' => $this->slug])
And add route with slug on your main.php
Look at my example.
First config urlManager in config.php in 'app/config' folder. In my case look like:
'components' => [
...
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
''=>'home/index',
'<slugm>-<id:\d+>-' => 'home/view',
],
],
.
...
],
and create link as fallow:
Url::to(['/home/view', 'id' => $model->home_id, 'slugm' =>$model->title_sr_latn])
and finaly url look like:
https://primer.izrada-sajta.rs/usluge-izrade-sajtova-1-
I want to upload a logo for my reports.
This is a snippet from my uploadLogo function
$file = $request->file;
Storage::disk('logo')->put('logo.png', $file);
I've created a logo profile in filesystems.php like this.
'logo' => [
'driver' => 'local',
'root' => public_path() . '/img',
'url' => env('APP_URL').'/public',
'visibility' => 'public',
],
But it eventually created the file in a 'random' ( or misunderstood ) location with a random name.
public\img\logo.png\M4FGLpZzAsyxn8NHiJLxo95EoP7I3CkIWvqkiQsv.png
What am I missing in my setup here?
You can store the file directly of the request's file (UploadedFile) object. And use storeAs to save by the name you supply. The Storage::put and UploadedFile::store` methods generate random names for the filed being stored.
$path = $request->file->storeAs('img', 'logo.png', 'logo');
More info https://laravel.com/docs/8.x/filesystem#storing-files and https://laravel.com/docs/8.x/requests#storing-uploaded-files
I am trying to hide the Image URL Larval 7 Application.
My image actual path is
storage/app/public/images/product_images
I have created a storage link using bellow command
php artisan storage:link
this creates a symbolic link in public directory "storage" to "storage/app/public/"
After that, I have created a new disk in config/filesystems.php
'images' => [
'driver' => 'local',
'root' => storage_path('app/public/images'),
'url' => env('APP_URL') . '/images',
'visibility' => 'public',
],
in my view I have written this code to access the image
<img class="img-fluid" src="{{Storage::disk('images')->url('/product_images/'.$products_image)}}">
$products_image is getting the correct image name but the image is not showing.
Is it possible to achieve what I am trying to achieve?
and what I am doing wrong?
You are missing the storage part of the URI for the url for that disk in the configuration.
fix your url env('APP_URL') . '/storage/images' as it is stored in storage_path() so you need to append storage
`
'images' => [
'driver' => 'local',
'root' => storage_path('app/public/images'),
'url' => env('APP_URL') . 'storage/images',
'visibility' => 'public',
],
I've a problem, I'm trying test my aplicattion with PHPUnit, in that aplicattion I've multiple forms where the user can upload files, and since Admin can upload differents files, I'm trying test a form where the admin can upload an image, and an audio, but I don't get it; here's my code:
public function testCreateAudiobooks()
{
Storage::fake('uploads/audiobooks/cover_pages');
Session::start();
$response = $this->json('POST', 'admin-audiobooks', [
'audiobook_title' => 'Audiolibro con Unit',
'audiobook_description' => 'DescripciĆ³n de audiolibro desde Unit',
'audiobook_author' => 'PHPUnit',
'audiobook_section' => 'Pruebas',
'audiobook_keywords' => 'Unit',
'audiobook_storyteller' => 'Luis',
'audiobook_duration' => '15',
'audiobook_visibility' => 'Visible',
'audiobook_cover_page' => UploadedFile::fake()->image('45.png'),
'audiobook_location' => UploadedFile::fake(),
'_token' => csrf_token()
]);
Storage::disk('uploads/audiobooks/cover_pages')->assertMissing('45.png');
$response->assertRedirect();
}
As you can see, I pass the UploadedFile in audiobook_cover_page, but I dunno how can pass something similar for the audiobook_location
I found this artcile, and I try do something similar, but still didn't
If someone can help me, I'll be really gratefull!