skip to Main Content

carousel.blade.php

    <div class="container">
        <div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel">
          <div class="carousel-inner">
      
            @foreach($sliders as $key => $slider)
                <div class="carousel-item {{$key == 0 ? 'active' : ''}}">
                    <img class="d-block w-100" src="{{ asset('img/promotion/' . $slider->img) }}" alt="promotion">
                </div>
            @endforeach
      
          </div>
          <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Previous</span>
          </button>
          <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Next</span>
          </button>
        </div>
    </div>

route web.php

Route::get('carousel', [AppHttpControllersCarouselController::class, 'index']);

carouselController.php

namespace AppHttpControllers;

use IlluminateHttpRequest;

class CarouselController extends Controller
{
    protected $promotion;
    function __construct( AppRepositoriesroda2PromotionRepo $promotion)
    {
        $this->promotion = $promotion;
    }
    public function index()
    {
        $sliders = $this->promotion->getWhereAll(['group_type' => 'R2']);
    
        return view('frontend.carousel', compact('sliders'));
    }
}

2

Answers


  1. Chosen as BEST ANSWER

    $this->promotion->getWhereAll(['group_type' => 'R2']) is get PromotionRepo

    <?php
    namespace AppRepositoriesroda2;
    use AppModelsCarousel;
    use AppRepositoriesAppEloquent;
    
    class PromotionRepo extends AppEloquent
    {
        protected $model;
        public function __construct(Carousel $model)
        {
            $this->model = $model;
        }
    }
    

    carousel models

    <?php
    
    namespace AppModels;
    
    use IlluminateDatabaseEloquentFactoriesHasFactory;
    use IlluminateDatabaseEloquentModel;
    
    class Carousel extends Model
    {
        use HasFactory;
        protected $table = 'carousels';
        protected $fillable = [
            'user_id',
            'state',
            'img',
            'group_type',
        ];
    }
    

  2. We don’t know what $this->promotion->getWhereAll(['group_type' => 'R2']) actually returns, but the return of the index function inside the controller class should be something like

    return view('frontend.carousel', ['sliders'=>$sliders]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search