2017-07-26 51 views
1

這是我的代碼。如何正確定義$ bgprofile?我想知道爲什麼$ bgprofile undefine錯誤出現,如果我沒有放置isset。 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('[email protected]') }}" 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('[email protected]') }}" 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', '[email protected]'); 
+0

這似乎很好,問題是什麼?你沒有輸出?還是僅僅是那些不起作用的圖像? – Jerodev

+0

如何從'SettingController.php'傳遞'$ themes'?我認爲,它應該是'$ bgprofiles'。正確? –

回答

0

你是哪裏定義$bgprofilesettings.blade.php文件?你傳遞給視圖的變量是$bgprofiles(複數),所以如果沒有定義任何地方 - 你肯定會被拋出一個錯誤,除非你添加isset條件,在這種情況下,它會發現它不是沒有進一步定義和進行。

0

我編輯控制器:

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

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

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

(使它singuler),它仍然是相同的。我看不到我希望看到的照片集。