vendredi 28 juin 2019

How to display category name from different table instead of category id

I have 2 tables - one with forum category name field called "disp_name" and "ID" called "forum_cat" and onother with forum posts id, forum post content and cat_id and more called "forum"

I have model "Forum_cats"

    <?php

    namespace App;

    use Illuminate\Database\Eloquent\Model;

    class Forum_cats extends Model
    {

    protected $table = 'forum_cat';

    public $timestamps = false;

    }

and model "Forum"

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Forum extends Model
{   

protected $table = 'forum';

public $timestamps = false;

}

Controller :

public function index(){


    $forum = Forum::orderBy('timestamp', 'desc')->paginate(20);

//next variable is for different place
    $news = Neww::orderBy('date', 'DESC')->paginate(20);


    return view ('lapas.pamata.index',[
        'news'=>$news,
        'forum'=> $forum,
    ]);
}

Blade:

@foreach($forum as $forums)
          <li>
            <div class="media">
              <div class="media-body"> <a href="#" class="catg_title"> 
              </a> </div>
              <i class="far fa-comment-alt"></i>&nbsp; 
              Kategorija:
            </div>
          </li>
        @endforeach

so the view at the moment is like this where after "Kategorija" i have only category id

How to make after name "Kategorija" output field "disp_name" from table "forum_cat".

Someone can tell that there are lots of posts about my problem but i am trying to solve this problem all day. I know that its about hasOne, belongsTo and hasMany but i dont understand how correct us them on my code.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NllFEN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire