Я пытаюсь сделать троичную операцию в моем теге 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>
А вот результат исключения из Laravel:
<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)
Неопределенная переменная: campbanner
Это ошибка?Или я просто что-то напутал?
ОБНОВЛЕНИЕ
Вот мой контроллер:
<?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.'];
}
}