Laravel/Bootstrap 5 - Making a card row shrinks its image - php

I'm using Bootstrap's 5 card and Laravel to make a car card. When I try to make a row with cards, the image shrinks. If I remove the "row" class, its image fits perfectly. ¿How can I solve this issue?
<h1>Vehículos</h1>
<div class="row">
#foreach ($autos as $auto)
<div class="card" style="width: 18rem; border-radius: 25px;">
<a href="{{ URL('auto/'.$auto->id)}}">
<img src="{{ URL('images/'.$auto->foto)}}" class="card-img-top" alt="..." style="border-top-right-radius: 25px; border-top-left-radius: 25px;">
</a>
<div class="card-body">
<h5 class="card-title">{{$auto->marca." ".$auto->modelo}}</h5>
<p class="card-text">
Año: {{$auto->año}}
Kilometros: {{$auto->kilometros}}
Motor: {{$auto->motor}}
Combustible: {{$auto->combustible}}
Precio: $ {{$auto->precio}}
</p>
</div>
</div>
#endforeach
</div>
</div> ```
[1]: https://i.stack.imgur.com/TviHn.png

I had to reproduce the error on my own end and I found the issue. When using a bootstrap row , you have to add columns using the col class. So change your code to this
<h1>Vehículos</h1>
<div class="row">
#foreach ($autos as $auto)
<div class="col">
<div class="card" style="width: 18rem; border-radius: 25px;">
<a href="{{ URL('auto/'.$auto->id)}}">
<img src="{{ URL('images/'.$auto->foto)}}" class="card-img-top" alt="..." style="border-top-right-radius: 25px; border-top-left-radius: 25px;">
</a>
<div class="card-body">
<h5 class="card-title">{{$auto->marca." ".$auto->modelo}}</h5>
<p class="card-text">
Año: {{$auto->año}}
Kilometros: {{$auto->kilometros}}
Motor: {{$auto->motor}}
Combustible: {{$auto->combustible}}
Precio: $ {{$auto->precio}}
</p>
</div>
</div>
</div>
#endforeach
</div>
</div>
This would fix the issue of the image being shrinked.
SIDENOTE: Do note that the bootstrap col class has prefixes to make it adapt to different screens. You can check out the docs for more info.

Related

My live search using livewire is not working

I am doing a live search on livewire, my search term is already binded with the livewire controller, but when I add it to the where clause in render function, it still displays all the data on the table not the one i am searching. I tried replacing the searchterm with a string as keyword in LIKE and it works. It seems that i can't use the input in searchterm as a keyword in the where clause.
here is my controller;
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Item;
use Livewire\WithPagination;
class Items extends Component
{
use WithPagination;
public $searchTerm;
public function render()
{
$select = Item::where('itemName', 'LIKE', '%' . $this->searchTerm . '%')->paginate(6);
return view('livewire.items', ['items' => $select]);
}
}
this is my view
<div class="row browse mt-6">
<div class="col float-left category ">
<h4 class="float-left font-weight-bold">All Categories</h4>
<h4 class="float-left font-weight-bold">Men</h4>
<h4 class="float-left font-weight-bold">Women</h4>
</div>
<div class="col search-cat float-right">
<input type="text" id="search" placeholder="Browse Products" wire:model="searchTerm"/>
</div>
{{$searchTerm}}
</div>
<hr style="border-top: dotted 1px;" />
<div class="row w-100 p-1">
<table class="table-center">
<tbody>
<div>
#foreach($items as $item)
<tr class="mx-auto">
<div class="d-inline w-30 item-desc mx-auto m-1">
<h4 class="pt-1">{{ $item->itemName }}</h4>
<div class="">
<img src="items/{{ $item->itemPic }}.png" alt="" class="item-pic">
</div>
<div class="row">
<div class="col d-inline float-left">
Price: US ${{ $item->itemPrice }}
</div>
<div class="col d-inline float-right">
{{ $item->itemCOD }}</td>
</div>
</div>
</div>
</tr>
</tbody>
#endforeach
</div>
<hr style="border-top: dotted 1px;" />
<div class="pagination-content">
{{ $items->links('pagination::pagination-custom') }}
</div>
<hr style="border-top: dotted 1px;" />
</table>
</div>
There's two things here that could potentially cause problems,
Your tr element does not have wire:key, the value to wire:key must be unique across the entire page
Your view consists of multiple root elements (if this is your entire view), these are the three root-elements in your view - and in Livewire, its very important that the view only has one root element.
<div class="row browse mt-6">
<hr style="border-top: dotted 1px;" />
<div class="row w-100 p-1">
Also, as a sidenote, your loop also closes the tbody tag, which is odd, so I moved that out of the loop. It also doesn't quite make sense to put divs and hrs inside the table tag, those should probably be outside of the tabletag.
Here's the updated view, with wire:key on the tr and with the whole view wrapped in one div,
<div>
<div class="row browse mt-6">
<div class="col float-left category ">
<h4 class="float-left font-weight-bold">All Categories</h4>
<h4 class="float-left font-weight-bold">Men</h4>
<h4 class="float-left font-weight-bold">Women</h4>
</div>
<div class="col search-cat float-right">
<input type="text" id="search" placeholder="Browse Products" wire:model="searchTerm"/>
</div>
{{$searchTerm}}
</div>
<hr style="border-top: dotted 1px;" />
<div class="row w-100 p-1">
<table class="table-center">
<tbody>
<div>
#foreach($items as $item)
<tr class="mx-auto" wire:key="item-{{ $item->id }}">
<div class="d-inline w-30 item-desc mx-auto m-1">
<h4 class="pt-1">{{ $item->itemName }}</h4>
<div class="">
<img src="items/{{ $item->itemPic }}.png" alt="" class="item-pic">
</div>
<div class="row">
<div class="col d-inline float-left">
Price: US ${{ $item->itemPrice }}
</div>
<div class="col d-inline float-right">
{{ $item->itemCOD }}</td>
</div>
</div>
</div>
</tr>
#endforeach
</div>
</tbody>
<hr style="border-top: dotted 1px;" />
<div class="pagination-content">
{{ $items->links('pagination::pagination-custom') }}
</div>
<hr style="border-top: dotted 1px;" />
</table>
</div>
</div>
Have a look at this resource from the official Livewire docs,
https://laravel-livewire.com/docs/2.x/troubleshooting#dom-diffing-issues
Maybe because you not render component
Try add <livewire:name-component /> in parent view like this
<div class>
<livewire:name-component />
</div>

Bootstrap card animation when hover

I have view where I show dynamically some cards that grow when hover. This is my css:
.card-deck .card {
height:200px;
width: 200px;
transition: transform .1s;
}
.card-deck .card:hover {
-ms-transform: scale(1.25); /* IE 9 */
-webkit-transform: scale(1.25); /* Safari 3-8 */
transform: scale(1.25);
}
#media (min-width: 576px) {
.card-deck .card {
flex-basis: calc(50% - 30px);
/* #{$grid-gutter-width} */
}
}
#media (min-width: 768px) {
.card-deck .card {
flex-basis: calc(33.33% - 30px);
}
}
#media (min-width: 992px) {
.card-deck .card {
flex-basis: calc(25% - 30px);
}
}
.card-img-top {
width: 100%;
height: 75%;
object-fit: cover;
}
.card-title {
width: 100%;
height: 100%;
object-fit: cover;
}
And my home.blade.php:
<div class="container">
<div class="row">
<div class="col">
<div class="card-deck">
#forelse ($meetings as $meeting)
#csrf
<div class="card mb-3 bg-dark">
#if ($meeting['photoName'])
<img class="card-img-top" src="{{ url($meeting['photoName']) }}" alt="Foto de la asignatura">
#else
<img class="card-img-top" src="https://www.arqhys.com/general/wp-content/uploads/2011/07/Roles-de-la-inform%C3%A1tica.jpg" alt="Foto de la asignatura">
#endif
<div class="card-body bg-dark">
{{ $meeting->title }}
</div>
</div>
#empty
<h4> Nothing to show yet.</h4>
#endforelse
</div>
</div>
</div>
</div>
I have 2 problems here that I can't solve:
1- When a card grows, it's over those that are in the previous row but under the card below that, so part of the card is hidden, how can I fix that?
2- The rows are made up of 4 cards but if the number of cards is not multiple of 4, I want the last row incomplete, not full filled by 1, 2 or 3 bigger cards. How can I do that?
.card-deck has been dropped
Breaking Dropped .card-deck in favor of our grid. Wrap your cards in column classes and add a parent .row-cols-* container to recreate card decks (but with more control over responsive alignment).
-- https://getbootstrap.com/docs/5.2/migration/#card
<div class="container">
<div class="row">
<div class="col">
<div class="row row-cols-4 g-2">
#forelse ($meetings as $meeting)
#csrf
<div class="col">
<div class="card mb-3 bg-dark h-100">
Here is a working snippet with the 5th card wrapped:
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<div class="row row-cols-4 g-2">
<div class="col">
<div class="card h-100">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content.</p>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
<img src="..." class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
<style>
.card{
border: 2px solid black;
}
</style>```

Images I upload in Laravel don't show after I have tried many answers online. All the images I upload store alright but they don't display

I have this in view. It is able to upload alright but it won't show. Is there anything more I should add?
<div class="col-md-4">
<img class="img img-fluid img-thumbnail" src="/storage/profile_images/{{$profile->profile_image}}"/> </div>
here is my show.blade.php file
<div class="col-md-4">
<img class="img img-fluid img-thumbnail" src="/storage/profile_images/{{$profile->profile_image}}"/></div>
Here is the player.blade.php file:
#if(count($players) > 0)
<?php $index = 0; ?>
#foreach($players as $player)
<div class="col-md-4">
<div class="card mb-1" style="width:300px">
<div class="card-body">
<img class="img img-fluid img-thumbnail" style="height: 170px; width: 350px" src="/storage/profile_images/{{$player->profile_image}}">
</div>
<div class="card-footer">
<div class="row justify-content-center">
{{$names[$index]}}<br>
</div>
<div class="row">
<div class="col-10">
<span class="h6">Team: {{$player->current_fc}}</span><br>
<span class="h6">Position: {{$player->position}}</span><br>
</div>
</div>
</div>
</div>
</div>
<?php $index++; ?>
#endforeach
<div class="col-12 mt-3">
{{$players->appends(request()->input())->links()}}
</div>
#else
<p>No Players available</p>
#endif
Follow above your image issue will be resolved:
Step 1:
Delete storage folder from public
Step 2:
Inside your project run this command
player.blade.php
php artisan storage:link
Step 3:
Replace or change as per this:
show.blade.php
<div class="col-md-4">
<img class="img img-fluid img-thumbnail" src="{{ url('storage/profile_images/.$profile->profile_image) }}" /></div>
Step 4:
Replace or change as per you required:
#if(count($players) > 0)
<?php $index = 0; ?>
#foreach($players as $player)
<div class="col-md-4">
<div class="card mb-1" style="width:300px">
<div class="card-body">
<img class="img img-fluid img-thumbnail" style="height: 170px; width: 350px" src="{{ url('storage/profile_images/.$profile->profile_image) }}">
</div>
<div class="card-footer">
<div class="row justify-content-center">
{{$names[$index]}}<br>
</div>
<div class="row">
<div class="col-10">
<span class="h6">Team: {{$player->current_fc}}</span><br>
<span class="h6">Position: {{$player->position}}</span><br>
</div>
</div>
</div>
</div>
</div>
<?php $index++; ?>
#endforeach
<div class="col-12 mt-3">
{{$players->appends(request()->input())->links()}}
</div>
#else
<p>No Players available</p>
#endif
You can use the asset function like in the example below:
#php
$imgUrl = '/storage/profile_images/'.$profile->profile_image;
#endphp
<img class="img img-fluid img-thumbnail" src="{{ asset($imgUrl)}}"/>
Also make sure that the storage is linked using the following command:
php artisan storage:link

Trying to loop through database with bootstrap cards

Trying to loop through my database and to post a bootstrap card for each "board member" in my database. However, with my current code, they post on top of each other, and I need them in rows. Here is my current code.
<div class="row">
<div class="col-sm-4 my-4">
#if(count($boardMembers) > 0)
#foreach($boardMembers as $boardMember)
<div class="card">
<img class="card-img-top" src="img/user1.jpg" alt="">
<div class="card-body">
<h2 class="card-title">{{$boardMember->name}}</h2>
<p class="card-text">{!!$boardMember->description!!}</p>
</div>
</div>
#endforeach
#else
<p>No Members Found</p>
#endif
</div>
</div>
You need to loop the .col part:
#if(count($boardMembers) > 0)
#foreach($boardMembers as $boardMember)
<div class="col-sm-4 my-4">
<div class="card">
<img class="card-img-top" src="img/user1.jpg" alt="">
<div class="card-body">
<h2 class="card-title">{{$boardMember->name}}</h2>
<p class="card-text">{!!$boardMember->description!!}</p>
</div>
</div>
</div>
#endforeach
#else
<p>No Members Found</p>
#endif
This will create multiple .cols with .cards but make sure you style the <p>No Members Found</p> or you can make it inside a .col too

How do I loop through grid properly?

I'm currently working on a photo gallery index.
How can I make it so that my loop iterates all 4 columns and then proceeds making a new row?
This is my code:
<div class="row">
#foreach($photoGalleries as $photoGallery)
<div class="col-md-3">
<a href="{{ url('/photogalleries/' . $photoGallery->id) }}">
<img class="img-fluid" style="height: 200px; width: 200px;" src="/images/{{ $photoGallery->cover_image }}">
</a>
<h3>{{ $photoGallery->name }}</h3>
</div>
#endforeach
</div>
Now as you can imagine, it'll appear like this:
Alternative solution:
Add margin-top after the col-md-3 attribute, like so:
<div class="col-md-3" style="margin-top: 20px;">
</div>
$collectionOne = $photoGalleries->chunk(4);
#foreach($collectionOne as $collectionTwo)
<div class "row" >
#foreach($collectionTwo as $photoGallery)
<div class="col-md-3">
......
</div>
#endforeah
</div>
#endforeach

Categories