Php 在Laravel中显示特定广告/酒店的主视频

Php 在Laravel中显示特定广告/酒店的主视频,php,laravel,Php,Laravel,我正在为拉威尔的广告/房地产项目工作。我有多个视频库为每个单独的广告。我想能够选择其中一个视频单选按钮,使其成为该广告的主要视频(显示该特定视频旁边的广告)。我有很多关系,财产和视频。我正在尝试将我的is_main_视频列更新为1(如果它是main)或0(如果它不是),然后在我的视图中显示该视频(如果它是1)。我在控制器中写入该方法时遇到问题,我收到了成功消息,但我的is_main_视频列仍然为空。感谢您的帮助。这是我的表格和代码 properties (id, title, location,

我正在为拉威尔的广告/房地产项目工作。我有多个视频库为每个单独的广告。我想能够选择其中一个视频单选按钮,使其成为该广告的主要视频(显示该特定视频旁边的广告)。我有很多关系,财产和视频。我正在尝试将我的is_main_视频列更新为1(如果它是main)或0(如果它不是),然后在我的视图中显示该视频(如果它是1)。我在控制器中写入该方法时遇到问题,我收到了成功消息,但我的is_main_视频列仍然为空。感谢您的帮助。这是我的表格和代码

properties (id, title, location, price)

videos (id, filename_video, model_id, is_main_video)
在视频表中,model_id列是连接到属性表的外键

PropertyController.php

public function update(StorePropertyInfo $request, Property $property, Video $video)
{
    $videoExtensions = ['mp4', '3gp', 'wmv', 'flv', 'avi'];

    $image_arr = array_filter(explode(',', $request->image), 'strlen');
        foreach ($image_arr as $key => $value) {
            $file = explode('.', $value);
            ext = end($file);

            if (in_array($ext, $videoExtensions)) {

                $query = Property::query();

                if ($request->has('radio')) {
                    $request->get('radio');
                }

                if ($request->radio) {
                    $query->whereHas('videos', function ($query) use ($request) {
                        $query->where('is_main_video', 'like', '%' . $request->radio . '%');
                    });
                }

                $data = $query;

                $video->where('filename_video', $value)
                ->update([
                    'model_id' => $property->id,
                    'is_main_video' => $data
                ]);

            };

        $request->validated();

        return redirect()
            ->back()
            ->with('message', 'Property information updated');
        }
}
edit.blade.php

<input type="hidden" id="hideninput" data-src="property/{{$property->id}}/gallery"value="{{old('video',$video)}}" name="video">
@if (old('video', $video))
    @foreach (array_filter(explode(',',old('video', $video)), 'strlen') as $key =>$value)
        <div id="{{'div_video_'.$key}}" class="col-md-3" style="padding: 15px;">

            <input type="radio" name="radio" value="radio">Make main 

            <button data="{{$key}}" type="button" class="closebuttonvideo">
                <span aria-hidden="true">&times;</span>
            </button>

            <video name="video" id="{{'video_'.$key}}" data={{$value}} src="/storage/property/{{$property->id}}/gallery/{{$value}}" class="video-js vjs-default-skin" controls preload="auto" data-setup='{"inactivityTimeout": 0}' width="180" height="180"></video>

        </div>
    @endforeach
@endif
@foreach($property->videos as $video)
<input type="radio" name="main_video" value="{{ $video->id }}">Video {{ $video->id }}<br>
@endforeach
Property.php

protected $appends = ['is_main_video'];

public function videos()
{
    return $this->hasMany(Video::class, 'model_id');
}
Video.php

public function properties()
{
    return $this->belongsTo(Property::class);
}

我会部分重写,类似这样:

edit()
中的PropertyController.php;正在检索带有附加视频的属性

return view('edit', [
    'property' => Property::with('videos')->find(1),
]);
edit.blade.php

<input type="hidden" id="hideninput" data-src="property/{{$property->id}}/gallery"value="{{old('video',$video)}}" name="video">
@if (old('video', $video))
    @foreach (array_filter(explode(',',old('video', $video)), 'strlen') as $key =>$value)
        <div id="{{'div_video_'.$key}}" class="col-md-3" style="padding: 15px;">

            <input type="radio" name="radio" value="radio">Make main 

            <button data="{{$key}}" type="button" class="closebuttonvideo">
                <span aria-hidden="true">&times;</span>
            </button>

            <video name="video" id="{{'video_'.$key}}" data={{$value}} src="/storage/property/{{$property->id}}/gallery/{{$value}}" class="video-js vjs-default-skin" controls preload="auto" data-setup='{"inactivityTimeout": 0}' width="180" height="180"></video>

        </div>
    @endforeach
@endif
@foreach($property->videos as $video)
<input type="radio" name="main_video" value="{{ $video->id }}">Video {{ $video->id }}<br>
@endforeach