0

расшифрую вопрос, а то и сам не понял. Таблица связывает работников и работодателей

Schema::create('workers', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained();
            $table->foreignId('organization_id')->constrained();
            $table->boolean('active')->nullable();
            $table->timestamps();
        });

в классе описан метод сохранения/обновления

Service::updateOrCreate(['id' => $this->serv_id], [
            'organization_id'   => 
            'name'              => $this->name,
            'active'            => $this->active
        ]);

вопрос как в этом методе получить organization_id, зная id зологиненного пользователя с помощью по первой таблицы?

2
  • сделал так, но не работает public function render() { $this->userId = Auth::id(); $this->organization_id = DB::table('workers') ->select('organization_id') ->where('user_id', '=', $this->userId) ->get(); $this->services = Service::all(); return view('livewire.services'); }
    – RizONE
    20 дек 2020 в 13:47
  • public function store() { $this->organization_id = DB::table('workers') ->select('organization_id') ->where('user_id', '=', Auth::id()) ->where('active', '=', "1") ->get(); Service::updateOrCreate(['id' => $this->serv_id], [ 'organization_id' => $this->organization_id, 'name' => $this->name, 'active' => $this->active ]); } Получаю значение в виде "ключ - значение". Как теперь значение получить?
    – RizONE
    20 дек 2020 в 14:32

1 ответ 1

0
public function store() {
        $this->validate([
            'name'              => 'required',
        ]);

        $this->organization_id = DB::table('workers')
            ->select('organization_id')
            ->where('user_id', '=', Auth::id())
            ->where('active', '=', "1")
            ->value('organization_id');

        Service::updateOrCreate(['id' => $this->serv_id], [
            'organization_id'   => $this->organization_id,
            'name'              => $this->name,
            'active'            => $this->active
        ]);
    }

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.