我正试图在我的option标签中做一个三元操作。但是当我调用这个变量时,它变成了小写,而laravel却找不到它。
这是我的代码:
<select name="media_type" id="media_type" class="">
<option value="">Select an option</option>
<option value="image" {{ $campBanner->media_type == 'image' ? 'selected' : '' }}>Image</option>
<option value="video" {{ $campBanner->media_type == 'video' ? 'selected' : '' }}>Video</option>
</select>这是拉拉例外的结果:
<select name="media_type" id="media_type" class="">
<option value="">Select an option</option>
<option value="image" <?php echo e($campbanner->media_type == 'image' ? 'selected' : ''); ?>>Image</option>
<option value="video" <?php echo e($campbanner->media_type == 'video' ? 'selected' : ''); ?>>Video</option>
</select>ErrorException (E_ERROR) 未定义变量:大本营
是虫子吗?还是我搞砸了什么?
更新
这是我的控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\CampBanner;
use App\Http\Requests\StoreCampBanner;
class CampBannerController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('CampBanner.index', [
'campBanner' => CampBanner::all()
]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('CampBanner.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(StoreCampBanner $request)
{
CampBanner::create(
$request->validated()
);
return ['message' => 'Banner Camp baru telah ditambahkan'];
}
/**
* Display the specified resource.
*
* @param \App\CampBanner $campBanner
* @return \Illuminate\Http\Response
*/
public function show(CampBanner $campBanner)
{
return view('CampBanner.show', compact('campBanner'));
}
/**
* Show the form for editing the specified resource.
*
* @param \App\CampBanner $campBanner
* @return \Illuminate\Http\Response
*/
public function edit(CampBanner $campBanner)
{
return view('CampBanner.edit', compact('campBanner'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\CampBanner $campBanner
* @return \Illuminate\Http\Response
*/
public function update(StoreCampBanner $request, CampBanner $campBanner)
{
$campBanner->fill(
$request->validated()
)->save();
return ['message' => 'Camp Banner berhasil diperbarui'];
}
/**
* Remove the specified resource from storage.
*
* @param \App\CampBanner $campBanner
* @return \Illuminate\Http\Response
*/
public function destroy(CampBanner $campBanner)
{
$campBanner->delete();
return ['message' => 'Camp Banner berhasil dihapus.'];
}
}发布于 2019-01-04 17:49:42
把你的控制器代码,以便得到更好的帮助。
https://stackoverflow.com/questions/54034526
复制相似问题