Showing and hiding previous and next elements in a carousel laravel - laravel

Im newbie in Laravel and Bootstrap also.
I am trying to display data from database in carousel.
In database I have filled few rows with text and I would like to display each row on each slide. When I click on arrow, one row/slide hide and the other row/slide will show.
Now, I get all slide with text under each other... I cannot find some javascript which I can do this:
#foreach($cards as $card)
<div id="myCarousel" class="carousel slide" data-toggle="collapse" data-ride="carousel" data-interval="false">
<div class="carousel-inner">
<div class="carousel-item active">
<div class="carousel-caption">
<h3>...</h3>
<p class="carousel_text">{{ $card->text }}</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
#endforeach
Can you please somebody help me with this?

Try this:
<div id="myCarousel" class="carousel slide" data-toggle="collapse" data-ride="carousel" data-interval="false">
<div class="carousel-inner">
<?php $index = 0; ?>
#foreach($cards as $card)
<div class="carousel-item {{ $index == 0 ? "active" : "" }}">
<div class="carousel-caption">
<h3>...</h3>
<p class="carousel_text">{{ $card->text }}</p>
</div>
</div>
<?php $index++; ?>
#endforeach
</div>
<a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
Let me know if this works!
Thank you.

Related

The content of the view is shown below the sidebar

I'm having a problem.
I have the following Sidebar in a file called navbar.blade.php:
<div class="container-fluid">
<div class="row flex-nowrap">
<div class="col-auto col-md-3 col-xl-2 px-sm-2 px-0 bg-dark">
<div class="d-flex flex-column align-items-center align-items-sm-start px-3 pt-2 text-white min-vh-100">
<a href="/" class="d-flex align-items-center pb-3 mb-md-0 me-md-auto text-white text-decoration-none">
<span class="fs-5 d-none d-sm-inline">Menu</span>
</a>
<ul class="nav nav-pills flex-column mb-sm-auto mb-0 align-items-center align-items-sm-start" id="menu">
<li class="nav-item">
<a href="#" class="nav-link align-middle px-0">
<i class="fs-4 bi-house"></i> <span class="ms-1 d-none d-sm-inline">Home</span>
</a>
</li>
<li>
<a href="#submenu1" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
<i class="fs-4 bi-speedometer2"></i> <span class="ms-1 d-none d-sm-inline">Dashboard</span> </a>
<ul class="collapse show nav flex-column ms-1" id="submenu1" data-bs-parent="#menu">
<li class="w-100">
<span class="d-none d-sm-inline">Item</span> 1
</li>
<li>
<span class="d-none d-sm-inline">Item</span> 2
</li>
</ul>
</li>
<li>
<a href="#" class="nav-link px-0 align-middle">
<i class="fs-4 bi-table"></i> <span class="ms-1 d-none d-sm-inline">Orders</span></a>
</li>
<li>
<a href="#submenu2" data-bs-toggle="collapse" class="nav-link px-0 align-middle ">
<i class="fs-4 bi-bootstrap"></i> <span class="ms-1 d-none d-sm-inline">Bootstrap</span></a>
<ul class="collapse nav flex-column ms-1" id="submenu2" data-bs-parent="#menu">
<li class="w-100">
<span class="d-none d-sm-inline">Item</span> 1
</li>
<li>
<span class="d-none d-sm-inline">Item</span> 2
</li>
</ul>
</li>
<li>
<a href="#submenu3" data-bs-toggle="collapse" class="nav-link px-0 align-middle">
<i class="fs-4 bi-grid"></i> <span class="ms-1 d-none d-sm-inline">Products</span> </a>
<ul class="collapse nav flex-column ms-1" id="submenu3" data-bs-parent="#menu">
<li class="w-100">
<span class="d-none d-sm-inline">Product</span> 1
</li>
<li>
<span class="d-none d-sm-inline">Product</span> 2
</li>
<li>
<span class="d-none d-sm-inline">Product</span> 3
</li>
<li>
<span class="d-none d-sm-inline">Product</span> 4
</li>
</ul>
</li>
<li>
<a href="#" class="nav-link px-0 align-middle">
<i class="fs-4 bi-people"></i> <span class="ms-1 d-none d-sm-inline">Customers</span> </a>
</li>
</ul>
<hr>
<div class="dropdown pb-4">
<a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
<img src="https://github.com/mdo.png" alt="hugenerd" width="30" height="30" class="rounded-circle">
<span class="d-none d-sm-inline mx-1">loser</span>
</a>
<ul class="dropdown-menu dropdown-menu-dark text-small shadow">
<li><a class="dropdown-item" href="#">New project...</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Profile</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Sign out</a></li>
</ul>
</div>
</div>
</div>
<div class="col py-3">
Content area...
</div>
</div>
</div>
Then I have a second layout file (layout.blade.php):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
#vite(['resources/css/app.css', 'resources/js/app.js'])
<title>Document</title>
</head>
<body>
<x-navbar/>
{{$slot}}
</body>
</html>
Next I have the following view (index.blade.php) which I want to be shown not under the sidebar but in the space where there is the word Content area ... in the sidebar.
As I am doing, the contents of index.blade.php are shown below.
<x-layout>
#if (session('message'))
<div class="alert alert-success">
{{ session('message') }}
</div>
#endif
<div class="row margintitle">
<div class="col-12 col-md-8 d-flex justify-content-center">
<h1>List all customers</h1>
</div>
</div>
</x-layout>
Can anyone kindly help me?
You can use the x-slot tag
(refs: https://laravel.com/docs/9.x/blade#slots)
I simplified the code:
navbar.blade.php:
<div class="col py-3">
{{-- Content area... -- }}
{{ $slot }}
</div>
layout.blade.php:
<x-navbar>
{{ $navbarContent }}
</x-navbar>
{{ $slot }}
index.blade.php:
<x-layout>
<x-slot:navbar-content> navbar title </x-slot>
<div> other content </div>
</x-layout>

Laravel Livewire chat Messages do not push upwards when new chat message comes in

I am developing A laravel Livewire chat. I am able to create new chats but the does not push up the previous message. Instead, it remains invisible behind the chat box. When a pusher message comes in, the chat message div remains at its original position.
Here is my mobile.blade.php
<div class="chatArea changeW" wire:poll>
<div class="chatMessages">
#foreach($messagesByDay as $day=>$messages)
<p class="timeId">
#if($day == date('Y-m-d'))
Today
#else
{{$day}}
#endif
</p>
#foreach($messages as $message)
#if($message->from_id != auth()->user()->id)
{{-- youra --}}
<div class="message">
<div class="prof">
<p><img src="{{$user->avatar()}}" style="width:30px"></p>
</div>
<div class="messArea">
<div class="textM">{{$message->body}}</div>
<p id="sname">{{$user->name}}</p>
</div>
</div>
{{-- yuors --}}
#else
{{-- mine --}}
<div class="message mMess 1122334" data-number="1122334">
<div class="messArea">
<div class="textM">{{$message->body}}</div>
</div>
<div class="prof">
<p><img src="{{auth()->user()->avatar()}}" style="width:30px"></p>
</div>
</div>
#endif
#endforeach
#endforeach
<!--End of Chat cont-->
</div>
#livewire('chat.messages.mobile.create',['user'=>$user])
</div>
This is the code at create.blade.php
<div class="messageBox">
<div wire:loading>
sending...
</div>
<div class="textA"><textarea id="message" wire:model.lazy="body" rows="1" cols="30"
placeholder="Type your message here"></textarea></div>
<button wire:click.prevent="save({{$user}})" id="send" class="button-s1" tooltip="Send" flow="left"><span class="material-icons headerIcon"><svg
xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-send"
viewBox="0 0 16 16">
<path
d="M15.854.146a.5.5 0 0 1 .11.54l-5.819 14.547a.75.75 0 0 1-1.329.124l-3.178-4.995L.643 7.184a.75.75 0 0 1 .124-1.33L15.314.037a.5.5 0 0 1 .54.11ZM6.636 10.07l2.761 4.338L14.13 2.576 6.636 10.07Zm6.787-8.201L1.591 6.602l4.339 2.76 7.494-7.493Z" />
</svg></span></button>
</div>
My Code at Messages.blade.php
<div class="chat-conversation p-3 p-lg-4" data-simplebar="init">
<ul class="list-unstyled mb-0" wire:poll>
#foreach($messagesByDay as $day=>$messages)
<li>
<div class="chat-day-title">
<span class="title">
#if($day == date('Y-m-d'))
Today
#else
{{$day}}
#endif
</span>
</div>
</li>
#foreach($messages as $message)
#if($message->from_id == auth()->user()->id)
<li class="right">
<div class="conversation-list">
<div class="chat-avatar">
<img src="{{$message->from->avatar()}}" alt="">
</div>
<div class="user-chat-content">
<div class="ctext-wrap">
<div class="ctext-wrap-content">
<p class="mb-0">
{{$message->body}}
</p>
<p class="chat-time mb-0">
<i class="ri-time-line align-middle"></i>
<span class="align-middle">{{date('H:i A',strtotime($message->created_at))}}</span>
</p>
</div>
<div class="dropdown align-self-start">
<a class="dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<i class="ri-more-2-fill"></i>
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Copy
<i class="ri-file-copy-line float-end text-muted"></i>
</a>
<a class="dropdown-item" href="#">Save
<i class="ri-save-line float-end text-muted"></i>
</a>
<a class="dropdown-item" href="#">Forward
<i class="ri-chat-forward-line float-end text-muted"></i>
</a>
<a class="dropdown-item" href="#">Delete
<i class="ri-delete-bin-line float-end text-muted"></i>
</a>
</div>
</div>
</div>
<div class="conversation-name">{{$message->from->name}}</div>
</div>
</div>
</li>
#else
<li>
<div class="conversation-list">
<div class="chat-avatar">
<img src="{{$user->avatar()}}" alt="">
</div>
<div class="user-chat-content">
<div class="ctext-wrap">
<div class="ctext-wrap-content">
<p class="mb-0">
{{$message->body}}
</p>
<p class="chat-time mb-0">
<i class="ri-time-line align-middle"></i>
<span class="align-middle">{{date('H:i A',strtotime($message->created_at))}}</span>
</p>
</div>
<div class="dropdown align-self-start">
<a class="dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<i class="ri-more-2-fill"></i>
</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Copy
<i class="ri-file-copy-line float-end text-muted"></i>
</a>
<a class="dropdown-item" href="#">Save
<i class="ri-save-line float-end text-muted"></i>
</a>
<a class="dropdown-item" href="#">Forward
<i class="ri-chat-forward-line float-end text-muted"></i>
</a>
<a class="dropdown-item" href="#">Delete
<i class="ri-delete-bin-line float-end text-muted"></i>
</a>
</div>
</div>
</div>
<div class="conversation-name">{{$user->name}}</div>
</div>
</div>
</li>
#endif
#endforeach
#endforeach
</ul>
</div>

Laravel Carousel dynamic with carousel category array

MY SLIDER OF CATEGORY TEST IS DISPLAYED THIS WAY IN THE PICTURE i.e images appear below each other
enter image description here...I have tried change the category test with another category but i could not fix it.. i guess the issue mighty be how to display the active image slide first then the rest come after-wards
My view blade is
#foreach ($data['testSlider'] as $slide )
<div class="carousel slide" data-ride="carousel" id="carousel-1">
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="w-100 d-block" id="imgslide" src= "{{asset('images/' . $slide->image)}}" alt="Slide Image">
</div>
</div>
<div>
<a class="carousel-control-prev" href="#carousel-1" role="button" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carousel-1" role="button" data-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="sr-only">Next</span>
</a>
</div>
<ol class="carousel-indicators">
<li data-target="#carousel-1" data-slide-to="0" class=""></li>
<li data-target="#carousel-1" data-slide-to="1"></li>
<li data-target="#carousel-1" data-slide-to="2"></li>
</ol>
</div>
#endforeach
MY SLIDER CONTROLLER HAS
use Illuminate\Http\Request;
use App\Models\website\backend\Slider;
use App\Models\website\backend\SliderCategory;
public function test()
{
$data['slider'] = Slider::all();
$data['slidercategory'] = SliderCategory::all();
$data['testSlider'] = Slider::with([
'SliderCategory' => function ($attachmentQuery) {
$attachmentQuery->where('title', 'test Slider');
}
])->get();
return view('testboot', compact('data'));
}
Your images are repeating because you are making an entire carousel for each image instead of adding the images to the first carousel.
<div class="carousel slide" data-ride="carousel" id="carousel-1">
<div class="carousel-inner" role="listbox">
#foreach ($data['testSlider'] as $slide )
<div class="carousel-item {{ $loop->first ? 'active' : '' }}">
<img class="w-100 d-block" id="imgslide-{{$loop->index}}" src= "{{asset('images/' . $slide->image)}}" alt="Slide Image">
</div>
#endforeach
</div>
<div>
<a class="carousel-control-prev" href="#carousel-1" role="button" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carousel-1" role="button" data-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="sr-only">Next</span>
</a>
</div>
<ol class="carousel-indicators">
#foreach ($data['testSlider'] as $slide )
<li data-target="#carousel-1" data-slide-to="{{ $loop->index }}" class="{{ $loop->first ? 'active' : '' }}"></li>
#endforeach
</ol>
</div>

Only one image is displayed in the image carousel in bootstrap and laravel

I am trying to display images in bootstrap carousel but am not able to loop. Only one image is shown but not sliding.Am using laravel in the back end. Please assist if you can this is the code.
This is the code:
<div class="container">
<div class="row">
<div id="imageCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
#foreach($images as $value)
<li data-target="#imageCarouselIndicator" data-slide-to="{{ $loop->index }}" class="{{ $loop->first ? 'active' : '' }}"></li>
#endforeach
</ol>
<div class="carousel-inner">
<h3>{{$product->title}}</h3>
#foreach($images as $image )
<div class="item image {{ $loop->first ? 'active' : '' }}">
<div class="carousel-item active">
<img src="/images2/{{$image->filename}}" alt="{{$image->title}}">
</div>
</div>
#endforeach
</div>
<a class="carousel-control-prev" href="#imageCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#imageCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
Try this:
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
#foreach($images as $image )
<div class="carousel-item {{ $loop->first ? 'active' : '' }}">
<img src="/images2/{{$image->filename}}"/>
</div>
#endforeach
</div>
</div>

Laravel - Why my code isnt displaying all the collapses ?

This code need to display all "subcategory" for each "subcategories"
But the view result is the first subcategory only.
Where i missed please ?
View 1 :
#foreach($treeView as $category)
<div class="collapse multi-collapse collapse in " id="8" >
<div class="col-md-2"> {{ $category->account_name}}</div>
<div class=" float-right"><button class="btn btn-success" data-toggle="collapse" data-target="#{{ $category->id}}8" aria-expanded="false" aria-controls="{{ $category->id}}8" #click="getSubaccount(); getNumberrawaccount();">
<span class="glyphicon glyphicon-eye-open"></span></button></div>
<br>
<div class="list-group">
#if(count($category->subcategories))
#include('tree2',['subcategories'=>$category->subcategories])
#endif
</div>
#endforeach
View 2 : tree2
<div class='list-group'>
<br>
#foreach($subcategories as $subcategory)
<div class="list-group col-md-12">
<div class="collapse multi-collapse" id="{{ $category->id}}8" >
<div class="col-md-4"> {{ $subcategory->subaccount_name }}</div>
<div class=" float-right"><button class="btn btn-success" data-toggle="collapse" data-target="#{{ $subcategory->id}}" aria-expanded="false" aria-controls="collapseExample2">
<span class="glyphicon glyphicon-eye-open"></span></button></div>
</div>
</div>
#endforeach
</div>
Thank you

Resources