How to find last row from second table, along with its first table row

Posted 4 months ago by vinubangs

I have two tables. Journals and volumes.

Journals have fields id, journalname

volumes have fields id, journal_id, volumename

volumes have many rows with same journal_id.

controller method is:

public function index()
    {
       $volumes = journal::with('volume')->get();
        return view('welcome',compact('volumes '));
    }

model journal is:

use App\volume;

class journal extends Model
{
   function volume()
     {
          return $this->hasmany(volume::class, 'journal_id');
     }
}

Above is giving, all rows from volumes table along with its related journal_id.

But I need only last row from volumes table along with its related journal_id.

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