如果我不放置isset,为什么$ bgprofiles是unfine?

时间:2017-07-26 09:55:27

标签: laravel

这是我的代码。如何正确定义$ bgprofile?我想知道如果我不放置isset,为什么会出现$ bgprofile undefine错误。 Evenso,除了看之外,我没有看到出现的图片集。任何线索?下面我发布了我的SettingController.php,Setting.blade.php和Routes.php。

SettingController.php

public function getBackgroundProfile(Request $request)
{
    $domain = $_SERVER['SERVER_NAME'];
    $user = User::where('domain', $domain)->first();

    $bgprofiles = DB::table('user_bgprofile')->where('user_id', $user->id)->get();    

    return view('soulfy.setting', [
            'bgprofiles' => $bgprofiles,
            'user' => $user,
        ]);
}

Setting.blade.php

     <form action="{{URL::to('/home/theme')}}" method="post"> 
                                    <span class="setting-name">THEME</span>

                                    <!-- <form method="POST" action="/posts"> -->
                                    {{ csrf_field() }}  
                                    <span class="setting-value center">

                                    <select name="menu">
                                        <option value="">All</option>
                                        <option value="Handicraft">Handicraft</option>
                                        <option value="Farming">Farming</option>
                                        <option value="Services">Services</option>
                                        <option value="Tour & Travel">Tour & Travel</option>
                                        <option value="Trading">Trading</option>
                                        <option value="Fishery">Fishery</option>
                                        <option value="Lifestyle">Lifestyle</option>
                                        <option value="Music">Music</option>
                                        <option value="Property">Property</option>
                                        <option value="Hobby">Hobby</option>
                                        <option value="Politic">Politic</option>
                                    </select>


                                    <input type="submit" value="Submit">                                        
                                    <br><br>

                                    </span>
                                    </form>

                                    <form action="{{ action('SettingController@SendPicture') }}" method="post">
                                    {{ csrf_field() }}

                                    <table>
                                        @foreach ($themes->chunk(3) as $chunk)
                                            <tr>
                                            @foreach ($chunk as $theme)
                                                <td>
                                                    <a href="{{url('/')}}/uploads/theme/{{$theme->pic_name}}.jpg" data-lightbox="image-gallery" data-title="{{$theme->pic_name}}" >
                                                    <img width="100px"
                                                        height="100px"
                                                        src="{{url('/')}}/uploads/theme/{{$theme->pic_name}}.jpg"/></a> 
                                                    <input type="checkbox" name="pic[{{$theme->pic_name}}]" value="{{$theme->pic_name}}"/>
                                                </td>
                                            @endforeach
                                            </tr>
                                        @endforeach
                                    </table>

                                    @if ( $themes->currentPage() != 1)
                                    <a href="{!! $themes->previousPageUrl() !!}"> << </a>@endif

                                    {!! $themes->currentPage() !!} of {!! $themes->lastPage() !!}

                                     @if ( $themes->currentPage() !=  $themes->lastPage())
                                    <a href="{!! $themes->nextPageUrl() !!}"> >> </a>@endif


                                    <input type="submit" value="Purchase">  
                                    </form>


                                    <form action="{{ action('SettingController@getBackgroundProfile') }}" method="post">
                                    {{ csrf_field() }}

                                    <table>
                                    @if(isset($bgprofile)) {

                                        @foreach ($bgprofiles->chunk(3) as $chunk)
                                            <tr>
                                            @foreach ($chunk as $bgprofile)
                                                <td>
                                                    <a href="{{url('/')}}/uploads/bgprofile/{{$bgprofile->bgprofile}}.jpg" data-lightbox="image-gallery" data-title="{{$bgprofile->bgprofile}}" >
                                                    <img width="100px"
                                                        height="100px"
                                                        src="{{url('/')}}/uploads/bgprofile/{{$bgprofile->bgprofile}}.jpg"/></a> 
                                                    <input type="checkbox" name="pic[{{$bgprofile->bgprofile}}]" value="{{$bgprofile->bgprofile}}"/>
                                                </td>
                                            @endforeach
                                            </tr>
                                        @endforeach

                                        }

                                    @endif 
                                    </table>



                                    </form>

routes.php文件

   Route::get('home/bgprofile', 'SettingController@getBackgroundProfile');

1 个答案:

答案 0 :(得分:0)

您在$bgprofile文件中定义settings.blade.php的位置?您传递给视图的变量是$bgprofiles(复数),因此如果在任何地方都没有定义 - 除非您正在添加,否则您将被引发错误isset条件,在这种情况下,它会看到它没有被定义,也没有继续进行。