Back

Eloquent relationship with 2 tables showing all records


UncleGreg posted 2 weeks ago

I have a Model order which has relations with the address model. The model address has many streets with different building numbers. Let's say New Street 20, New Street 21 etc.

When I enter a street, let it be New Street 20, it has to display devices located only in this address. displays in device but with order_id

my url i browser: http://127.0.0.1:8000/wymiany/3/6

3- is Order_id

6 - is Adress_id

The data form database output :

3 - is Adress_id

4 - is Device id

The correct should be null because i havent devices in adress_id = 6.

i think my problem is in this function:

public function item($id)
    {
        $adres= Adres::find($id);
        return view('wymiany/adres.show', compact('adres'));
    }

Adres controller

use App\Order;
use App\Adres;
class OrderAdresesController extends Controller
{
    protected $fillable = [];
    public function show(Order $id)
    {
       $wymiany=Order::find($id);
       return view('wymiany.item', compact('wymiany'));
    }
    public function store()
    {
        // dodaawanie adresu w zleceniu dla id_zlecenia
        //order_id hard taken from view in filed hidden value {{ $wymiany }}
        $wymiany = Adres::create(request(['ulica','nr_budynku','order_id']));
        return back();
    }
        public function item($id)
    {
        $adres= Adres::find($id);
        return view('wymiany/adres.show', compact('adres'));
    }
}

Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us