如何str_slug进入模型?

时间:2017-08-18 15:40:52

标签: laravel laravel-5 laravel-5.2

search.blade.php

@foreach($search as $item)
<div class="post">
    <a href="{{url($item["ID"].'/'.$item["row_name"]).'.html'}}">
</div>
@endforeach

SearchController.php

public function postSearch(SearchRequest $request){

        $search_key = $request->input('search');
        $key_space  = str_slug($search_key," ");
        $search     = moives::where('row_name','like',"%$key_space%")
                    ->orderBy('id','DESC')
                    ->get();
        if(count($search) > 0){
            return view('user.pages.search',compact('search','search_key'));        
        } 
        else {
            return view ('user.pages.search')->withMessage('No Details found. Try to search again !');
        }
    }

网址结果:

http://lar.dev/blog/11609/Beauty%20and%20the%20Beast.html

但我想要结果:

http://lar.dev/blog/11609/Beauty-and-the-Beast.html

这里的条件是我无法向数据库添加列,我只能从数据库中检索数据。

2 个答案:

答案 0 :(得分:0)

为了将-使用str_slug这样的单词划分为:

str_slug($string,"-");

答案 1 :(得分:0)

试试这个:

<a href="{{url(str_slug($item["ID"].'/'.$item["row_name"],'-')).'.html'}}">