這是我的代碼。如何正確定義$ 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]');
這似乎很好,問題是什麼?你沒有輸出?還是僅僅是那些不起作用的圖像? – Jerodev
如何從'SettingController.php'傳遞'$ themes'?我認爲,它應該是'$ bgprofiles'。正確? –