I want to make a N-N relationship between clients and rooms. I have this method to make that happen:
public function booking(Request $request, Client $client)
{
$room = DB::table('rooms')->where('id', '=', $request->roomname)->get();
//$client = DB::table('clients')->where('id', '=', $client)->get();
dd($client);
//$client = Client::find(10);
$clients = Client::query();
//$clients = Client::all();
$room->clients()->attach($client->id);
return redirect(route('reservation.index'));
}
But I am getting Method Illuminate\Support\Collection::clients does not exist. I tried to get all data from DataBase and query but i did'nt work. When I use $clients = Client::all(); and $room->clients->attach($client->id); I got this message: Property [[{"id":1,"name":"Mounir El imlahi","phone":"516421515","email":"[email protected]","created_at":"2020-05-13T08:09:49.000000Z","updated_at":"2020-05-13T08:09:49.000000Z"}]] does not exist on this collection instance.