我希望select中的某些选项(例如main_title=banner
,main_title=law
和main_title=faq
)仅对super_admin可见。
main_title.blade.php
<div class="form-group">
<label for="main_title">{{ trans('labels.main_title') }}</label>
<select v-model="post.main_title | mainTitle" name="main_title" id="main_title" class="form-control">
@foreach($main_title_options as $option)
<option {{ old('main_title') == $option->value ? 'selected="selected"' : '' }} value="{{ $option->value }}">
{{ trans('labels.'.$option->value) }}
</option>
@endforeach
</select>
</div>
我的PostController:
public function create()
{
$time = \Carbon\Carbon::now();
list(
$images,
$documents,
$medias,
$categories,
$main_title_options,
$event_type_options,
$event_halls,
) = $this->repo->getPostCreateEditdata();
$edit = false;
\JavaScript::put(compact('tags', 'categories', 'images', 'documents', 'medias'));
return view('posts.create-edit', compact(
'main_title_options',
'main_title',
'event_halls',
'event_type_options',
'time',
'edit'));
}
我尝试了一些方法,但是没有成功。
@if(Auth::user()->hasRole(['super_admin']))
在这里做什么?
public function getPostCreateEditdata()
{
$images = Document::whereFiletype('image')->with(['users'])->orderBy('created_at', 'desc')->limit(20)->get();
$documents = Document::whereFiletype('document')->with(['users'])->orderBy('created_at', 'desc')->limit(20)->get();
$medias = Document::whereFiletype('media')->with(['users'])->orderBy('created_at', 'desc')->limit(20)->get();
$categories = Taxonomy::whereType('category')->get();
$main_title_options = Settings::whereName('post_main_title_option')->get();
$event_type_options = Settings::whereName('post_event_type_option')->get();
$event_halls = Settings::whereName('event_hall')->get();
//documents are lazy loaded and we load only 20 at first, so we need to include the ones from old input if any
if (old('documents'))
$documents = $documents->merge(Document::whereIn('id', old('documents'))->get());
return array($images, $documents, $medias, $categories, $main_title_options, $event_type_options, $event_halls);
}
在此先感谢您,并原谅我的干预,并以较差的英语发言。