Laravels - Cannot Show Image after Upload and Save in Storage - laravel

I will show the upload image but it shown a thumbnail,
here is my Controller Code Upload a image file
$file = $request->file('images')->getClientOriginalName();
$filename = time().$file;
$path = base_path('/Uploads');
if($request->hasFile('images')){
$file = $request->file('images');
$file->move($path, $filename);
DB::table('books')->insert($filename);
return redirect('home')->with('status', 'insert succesfully');
}
else {
dd('Request Hash No File!');
}
Here is my view
#foreach ($booksDTL as $deTailsB)
<div class="col-md-4">
<img src="{{ asset('Uploads/'.$deTailsB->images) }}" width="100%" height="100%" title="{{ $deTailsB->images }}"/>
</div>
<div class="col-md-6">
<H1>{{ ucfirst(trans($deTailsB->name)) }}</H1>
<p>{{ strtoupper($deTailsB->author) }}</p>
</div>
#endforeach
Here is the controller to show data
public function detailBook($id)
{
$booksdetail = DB::table('books')->where('id', $id)->get();
return view ('details', ['booksDTL'=>$booksdetail]);
}
and here is when i run the code
enter image description here
The upload file save into folder 'Uploads' the folder is in the out of public folder, I already run the php artisan storage:link. But the upload picture still shown in thumbnail. Do you have any suggestion to this?

Related

When I upload a image It Does not show on database in Laravel 9

My problem is: When i click to send button with form. All information has been upladed to database exept image. That's why i could not catch to image from database to show users.
Here is the Migration Codes:
public function up()
{
Schema::create('haberler', function (Blueprint $table) {
$table->id();
$table->string('baslik')->default('');
$table->string('kategori')->nullable();
$table->string('icerik')->nullable();
$table->string('resim')->nullable();
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();
});
}
Here is the function codes
public function yenihaberekle(Request $request){
$request->validate([
'kategori'=>'required',
'baslik'=>'required|min:6|max:50',
'icerik'=>'required|min:50',
'resim' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$file_name = time() . '.' .request()->resim->getClientOriginalExtension();
request()->resim->move(public_path('images', $file_name));
$baslik = $request->baslik;
$kategori = $request->kategori;
$icerik = $request->icerik;
$stu = new haberler();
$stu->baslik = $baslik;
$stu->kategori = $kategori;
$stu->icerik = $icerik;
$stu->save();
return redirect()->back()->with('success','Haber veya Kampanya Başarıyla Eklenmitir. / News or Campaing has added by succesfuly');
}
and i try to catch code on front page
<div class="row">
#foreach($haberler as $haberler)
<div class="col-md-4 mb-30">
<div class="item">
<div class="position-re o-hidden"> <img src="{{ asset('images/'. $haberler->resimler) }}" alt="">
<div class="date">
<span>{{$haberler->created_at->format('M') }}</span> <i>{{$haberler->created_at->format('d') }}</i>
</div>
</div>
<div class="con"> <span class="category">
{{$haberler->kategori}}
</span>
<h5>{{$haberler->baslik}}</h5>
</div>
</div>
</div>
#endforeach
</div>
<div class="row">
and addnews blade i mean form
<form method="post" action="{{url('panel/news/addnews/yenihaberekle')}}" enctype="multipart/form-data">
Allright guys. I fixed to problem.
First, I forgot in the function:
$resim = $file_name;
Second, in my view blade my code was:
<img src="{{ asset('images/'. $haberler->resimler) }}"
But my function was resim so now it works.
thank you

Bootstrap dynamic slider in Laravel image is not showing

I am trying to implement bootstrap carousel dynamically from input in Laravel. My slider is working properly but the image is not showing.
slider code
#foreach($sliders as $key => $slider)
<div class="carousel-item {{$key == 0 ? 'active' : '' }}">
<img src="{{url('images/slider-rms', $slider->image)}}" class="d-block w-100" alt="...">
</div>
#endforeach
The backend and slider is working fine. But I am not sure about the path.
The image folder is : public->images->slider-rms
Image saving code
$slider = new Slider();
if($request->hasFile('slider')) {
// image that inserted
$image = $request->file('slider');
$img = time(). '.'.$image->getClientOriginalExtension();
$image->move('images/slider-rms/',$img);
$slider->image = $image;
}
$slider->save();

How do I display images in a footer?

I have stored logos in the database and want to display them in the footer which is included #include('layouts.footer'). I am fetching images from the database using this code
public function show(){
$logo = DB::table('logos')->get();
return view('layouts.footer',['logo'=>$logo]);
}
I want to display these images in the footer using
<div class="footer">
#foreach($logo as $l)
{{ $l->company_name}}
{{ $l->company_logo}}
#endforeach
<p class="footer-text">© Copyright <?php echo date("Y"); ?> Hotel Store Partners</p>
</div>
but returns an error "undefined variable logo".
What is the correct way to display the images in the footer?
Try Using View Composer
In you AppserviceProvider boot method you can gather these name and pass to all Views at once.
Reference
Two ways you can achieve this:
1. Put this code in footer.
#php
$logo = DB::table('logos')->get();
#endphp
<div class="footer">
#if(count($logo))
#foreach($logo as $l)
{{ $l->company_name}}
{{ $l->company_logo}}
#endforeach
#endif
<p class="footer-text">© Copyright <?php echo date("Y"); ?> Hotel Store Partners</p>
</div>
But this method is a bad practice
Create FooterComposer
public function compose(View $view)
{
$logo = DB::table('logos')->get();
$view->with(['logo'=>$logo]);
}
Now $logo will be accessible in footer.
I have used View Composer.
In AppServiceProvider boot method, I added this code:
public function boot()
{
View::composer('layouts.app', function($view){
$view->with('logo', Logo::all());
});
}
In the Controller, I used this code:
return view('layouts.footer');
In the footer, I used this code:
<footer>
#foreach($logo as $l)
<p>{{ $l->company_name }}</p>
<img src="https://partners.hotelstore.co.ke/public{{ $l->company_logo }}" style="width:100px; height:75px;">
#endforeach
<p class="footer-text">© Copyright <?php echo date("Y"); ?> Hotel Store Partners</p>
</footer>
This is what finally displayed the images on the footer.

category product photo are not add my frontpage

everything is ok but not show the category page.it is the code which i used that my project upload all image
if ($request->file('image')){
$file = $request->file('image');
$photo = time().$file->getClientOriginalName();
$destination =public_path() . '/uploads/category';
$file->move($destination, $photo);
$category->image= $photo;
}else{
$category->image= 'dummy_cat.png';
}
it is controller code
'featuredCategories'=>Category::Where('status',1)->where('isFeatured',1)->get(),
its my front page code
#foreach($featuredCategories as $category)
<div class="col-sm-2">
<a href="{{route('category.show',$category->slug)}}"
class="tt-promo-box tt-one-child hover-type-2">
<img src="{{asset('uploads/category'.$category->image)}}"**strong text**
data-src="{{asset('uploads/category'.$category->image)}}" alt="">
<div class="tt-description">
<div class="tt-description-wrapper">
<div class="tt-background"></div>
<div class="tt-title-small">{{strtoupper($category->name)}}</div>
</div>
</div>
</a>
</div>
#endforeach
it is my front page image
enter image description here
"look #male #female category add but not show the category upload photo" that is that main problem i face this ..
not show the just image my front page

I have uploaded a pdf file and when try to open it on my website it's showing file not found

I am trying to open a pdf file when I click on my website. The PDF is uploaded from the admin, but it's showing not found 404
view
<div class="entry-content">
<a target="_blank" href="{{$post->file}}">
<p style="font-size: 18px;color: #468b10;">
{{ $post->content }}
</p>
</a>
</div>
Controller
if (request('file')) {
$file = request('file');
$file=$file_name::get($file);
$file_name = time() . $file->getClientOriginalName();
$file->move('uploads/posts', $file_name);
$data['file'] = 'uploads/posts/'.$file_name;
}

Resources