Joins in laravel
#delete foregn key relavent data if main is delted
https://stackoverflow.com/questions/55677896/how-to-delete-a-foreign-key-constraint-in-laravel
# join in laravel
$data = Country::join('state', 'state.country_id', '=', 'country.country_id')
->join('city', 'city.state_id', '=', 'state.state_id')
->get(['country.country_name', 'state.state_name', 'city.city_name']);
#
$users = DB::table('users')
->join('contacts', 'users.id', '=', 'contacts.user_id')
->join('orders', 'users.id', '=', 'orders.user_id')
->select('users.*', 'contacts.phone', 'orders.price')
->get();
#
use Illuminate\Support\Facades\DB;
public function index(){
$usersDetails = DB::table('users')
->join('contacts', 'users.id', '=', 'contacts.user_id')// joining the contacts table , where user_id and contact_user_id are same
->select('users.*', 'contacts.phone')
->get();
return $usersDetails;