【问题标题】:concatenation in laravel controller goes wronglaravel 控制器中的连接出错
【发布时间】:2018-08-03 22:12:55
【问题描述】:
$data = <div class="">
    <h3><a class="text-dark" href=" url("/notice_details/'.$n->id.'")">'.$n->title.'</a>**</h3>

    <p class="text-muted"><i class="mdi mdi-calendar m-r-5"></i>Posted on :'.$n->date.'</p>

    <p class="font-13 text-muted m-b-0">
         '.$string.'
    </p>
</div>   

这是我的控制器(laravel 项目 5.5)中的代码想要在视图中生成 url,如我的项目中的 localhost/learning/notice_details/1 url() 返回 localhost/learning 但我无法生成正确的 href 链接可能有问题连接还是……??

【问题讨论】:

  • href="/notice_details/'.$n-&gt;id.'"

标签: laravel-5


【解决方案1】:

永远不要在你的控制器中使用 HTML。 - 在你的学习控制器中添加索引功能,然后再去查看,制作。

public function index(){
$n = Notice::all();
$string = "your string";
return view('notice_datails', compact('n', 'string'));
}

还有你的html

@foreach($n as $notice)
<div class="">
  <h3>
   <a class="text-dark" href="{{url("/notice_details/$notice->id")}} "> {{$notice->title}} </a>
  </h3>

  <p class="text-muted"><i class="mdi mdi-calendar m-r-5"></i>Posted on : {{$notice->date}}</p>

   <p class="font-13 text-muted m-b-0">
     {{$string}}
   </p>
</div>  
@endforeach

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    • 2021-01-04
    相关资源
    最近更新 更多