MattB
1 week ago
172
25
Laravel

How to delete from drop down list

Posted 1 week ago by MattB

I'm having a brain fart here. I have a list that's built from the entries in a table, which has a delete button beneath it. I want to be able to hit that button and delete whatever is selected in the list. So far I have this:

{!! Form::open(['method'=>'DELETE', 'action'=> ['[email protected]', $allBrands->id]]) !!}
               <div class="form-group {{$errors->has('company_id') ? 'has-error' : ''}}">
                   {!! Form::select('company_id', [''=>'Choose Brand'] + $allBrands,null, ['class'=>'form-control'])!!}
                   @if($errors->has('company_id'))
                       {{$errors->first('company_id')}}
                   @endif
               </div>
           <div class="form-group">
               {!! Form::submit('Remove Selected Brand', ['class'=>'btn btn-danger']) !!}
           </div>
           {!! Form::close() !!}

Controller:

public function index()
    {
        $allBrands = Company::pluck('company', 'id')->all();
        return view('admin.brands.index', compact('allBrands'));
    }

When I try to use the code as-is, I get error

Trying to get property 'id' of non-object

I can't see how to pass in the variable correctly it seems?

Please sign in or create an account to participate in this conversation.