duandao8607 2015-09-14 07:59
浏览 43
已采纳

在视图laravel 5中包含控制器

I'm new to laravel and I got stuck.

My problem is I want 2 sections (navigation, content) that has dynamic data

Here's some code Main Blade

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Portfolio</title>
</head>
    <body>
        <div class="navigation">
            @yield('menu')
        </div>
        <div class="content">
            @yield('content')   
        </div>
    </body>
</html>

portfolio blade

    @extends('main')

@section('content')
    @foreach($data as $portfolio)
        <a href="portfolio/{!!$portfolio->portfolio_url!!}"><img src='{{ URL::asset("images/$portfolio->picture.jpg") }}'/></a>
    @endforeach
@stop

and my navigation blade

@extends('main')
@section('menu')
    @foreach($menuknoppen as $menuknop)
            <a href='{{ URL::to("$menuknop->menu_url") }}'>{{$menuknop->menutitle}}</a>
    @endforeach
@stop

the portfolio blade has a controller, but also the menu blade has a controller

Edit1:

the problem is the navigation isn't showing even if I add static text

Edit2:

My controllers my portfolio controller

    /**
     * Show the profile for the given user.
     *
     * @param  int  $id
     * @return Response
     */
    public function index(){
        //here comes a whole list with what i've done
        $results = DB::table('projects')->get();
        //return $results;
        $data = array();
        foreach ($results as $key => $result) {
            $data[] = $result;
        }
        return view('portfolio.portfolio')->with('data', $data);
    }
    public function getProject($portfolio_url){
        //this gets the project thats clicked
        $results = DB::select('select * from projects where portfolio_url = ?', array($portfolio_url));
        return view('portfolio.single')->with('data', $results['0']);
    }

}

my navigation controller

class menuController extends Controller {

    /**
     * Show the profile for the given user.
     *
     * @param  int  $id
     * @return Response
     */
    // public function __construct($table){
    //  $results = DB::table($table)->get();

    //     return view('menu')->with('menuknoppen', $results);
    // }
    public function index(){
        $results = DB::table('navigation')->get();

        return view('menu')->with('menuknoppen', $results);
    }

}
  • 写回答

2条回答 默认 最新

  • douyun3799 2015-09-14 08:39
    关注

    Your main blade should be:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
     <meta charset="UTF-8">
     <title>Portfolio</title>
    </head>
    
    <body>
        <div class="navigation">
            @include('menu');
        </div>
        <div class="content">
            @yield('content')   
        </div>
    </body>
    </html>
    

    Your portfolio should be:

    @extends('main')
    
    @section('content')
      @foreach($data as $portfolio)
       <a href="portfolio/{!!$portfolio->portfolio_url!!}"><img src='{{ URL::asset("images/$portfolio->picture.jpg") }}'/></a>
      @endforeach
    
    @stop
    

    Navigation field should be:

    //Don't use extends here
     @foreach($menuknoppen as $menuknop)
            <a href='{{ URL::to("$menuknop->menu_url") }}'>{{$menuknop->menutitle}}</a>
    @endforeach
    

    Pass multiple data

    public function index()
    {
      $data = //data code;
      $results = // results code
      return view(portfolio.portfolio, compact('data', 'results'));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料