PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 16, 2022

[FIXED] How to get Current page Title of Relationship Model in Laravel?

 November 16, 2022     eloquent, laravel, laravel-6, laravel-6.2     No comments   

Issue

i have some fields in my database table, and i want to display title,description and keywords according to every page, Please let me know how i can display this. My database fields name are metatitle,metadesc,keyword

Here are my Controller code where i am displaying the property list...

    public function listtype($slug){
    $prtype= Listing::whereHas('proType',function($q) use($slug){
        $q->where('slug','like','%'.$slug.'%');
    })->paginate(50);
    return view('property-type',compact('prtype','title'));
}

Solution

You can do the following way:

 public function listtype($slug){
    $prtype= Listing::whereHas('proType',function($q) use($slug){
        $q->where('slug','like','%'.$slug.'%');
    })->with('proType')->paginate(50);
    dd($prtype); /** for checking **/ 
    return view('property-type',compact('prtype', $prtype));
 }


Answered By - Amit Senjaliya
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing