laravel 5.4 how to make page title with dynamic

人走茶凉 提交于 2020-05-10 08:44:46

问题


ihave a route to get artists initial letter.

this is my route

Route::get('/artists/{letter}', 'HomeController@showArtist')->where('letter', '[A-Za-z]+')->name('list');

and this is my controller showArtist method

public function showArtist($letter){
        $artists = Artist::where('name', 'like', $letter.'%')->get();
        return view('front.list',compact('artists'));
    }

what i want is in my list page that lists all artists alphabetically, i have made alphabetical menu like this A B C, FOR example if is clicked it will get all artists with initial letter A.

but my question is how can i make in my page title, foreaxmple like this "Artists begging with letter A" etc.

@section('title', 'artists begging with'. $artist->letter)

my question is how to find letter value?

please help how to accomplish this?


回答1:


You can pass selected letter value to Blade view like this:

return view('front.list',compact('artists','letter'));

instead of:

return view('front.list',compact('artists'));

And now in your view you can use:

<title>Artists begging with {{ $letter }}</title>



回答2:


If this is your master page title below

<head>
        <title>App Name - @yield('title')</title>
    </head>

then your page title can be changed in your blade page like below

@extends('layouts.master')

@section('title', 'Page Title')

@section('sidebar')
@parent

<p>This is appended to the master sidebar.</p>
@endsection

@section('content')
<p>This is my body content.</p>
@endsection


来源:https://stackoverflow.com/questions/42752133/laravel-5-4-how-to-make-page-title-with-dynamic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!