mardi 29 décembre 2020

send to repository class variable laravel from controller

i´m traying to do query into my repository to get galleries that to have a restaurant and i need seach for id. One restaurant´s gallery only can to have 10 images, but we can to have more than one restaurant. I need that when one restaurant will have a 10 images, it can´t upload any more and disable this restaurant.

sorry for my english, i hope that i can explain me correctly.

my controller:

if (auth()->user()->hasRole('admin')){
            $restaurant = $this->restaurantRepository->pluck('name', 'id');
        }else{
            $restaurant = $this->restaurantRepository->galleries()->myActiveRestaurants()->pluck('name', 'id');
        }
        // get all media gallery of restaurant
        //$media = $this->galleryRepository->getCountMedia();
        foreach($restaurant as $res){
            $res->cg = (count($res->galleries()->get()) == 10);
        }

        $hasCustomField = in_array($this->galleryRepository->model(), setting('custom_field_models', []));
        if ($hasCustomField) {
            $customFields = $this->customFieldRepository->findByField('custom_field_model', $this->galleryRepository->model());
            $html = generateCustomField($customFields);
        }
        return view('galleries.create')->with("customFields", isset($html) ? $html : false)->with("restaurant", $restaurant)/*->with('imagesRestaurant', $media)*/;

here i´m calling to model function galleries() where i have a function to get, restaurant_id

but in my web, result is:

Call to a member function galleries() on string

i need to get restaurant_id for call here my repository:

public function getCountMedia(){
        return Gallery::join("user_restaurants", "user_restaurants.restaurant_id", "=", "galleries.restaurant_id")
                        ->where('user_restaurants.user_id', auth()->id())->count();
    }

i don´t want auth()->id() i need restaurant_id for in my controller extract that restaurant to have 10 image

i hope that any can help me, please



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire