php - Laravel Get Join Data And Non Join Data
Get the solution ↓↓↓I am trying to get two tables data using join
// $participantstation = DB::table('participant_station')
// ->join('reviews', 'participant_station.id', '=', 'reviews.participant_station_id')
// ->select('reviews.*', 'participant_station.*')
// ->where('station_id',$stn->id)
// ->where('status', '100')
// ;
Still some partipant are not linked , that means - participant_station.id', '=', 'reviews.participant_station_id
if I try this code it only shows the linked participants
is there any way to show both linked and non-linked participants using such query?
Thank you
Answer
Solution:
Assuming you're trying to fetch all the details using Eloquent ORM here's what you can do:
$participantstation= ParticipantStation::join('participant_station', 'participant_station.id', '=', 'reviews.participant_station')->get(['reviews.*', 'participant_station.*']);
This will join the tables
Answer
Solution:
try this,
Model -> ParticipantStation.php:-
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ParticipantStation extends Model
{
public function reviews()
{
return $this->hasMany('App\Models\Review');
}
}
Model -> Review.php:-
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Review extends Model
{
public function participant_station()
{
return $this->BelongsTo('App\Models\ParticipantStation','participant_station_id');
}
}
In controller.php
use App\Models\ParticipantStation;
$participantstation = ParticipantStation::with('reviews')->where('station_id',$stn->id)->where('status', '100')->get();
//dd($participantstation);
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: gd library extension not available with this php installation.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.