• 1404/01/09

پاسخ تمرین - ذخیره در storage یا public :

درود . بعد از گذشت 4  سال از زمان آموزش و تمرین، من الان دیدم و پاسخ به سوالو دادم:

index:

<th>ذخیره در storage</th>

<td>    
	<label>        
		<input id="" type="checkbox" @if ($file->security === 1)checked@endif>    
	</label>
</td>

 

create:

section class="col-12 col-md-6 my-2">
  <div class="form-group">
    <label for="security">امنیت</label>            
    <select name="security" class="form-control form-control-sm" id="security">
      <option value="0" @if(old('security') == 0) selected @endif>امنیت فایل آنچنان مهم نیست</option>
      <option value="1" @if(old('security') == 1) selected @endif>در فضای امن</option>
    </select>
  </div>
@error('security')
  <span class="alert_required bg-danger text-white p-1 rounded" role="alert">
    <strong>{{ $message }}</strong>
  </span>
  @enderror
</section>

 

edit:

<section class="col-12 col-md-6 my-2">
  <div class="form-group">
    <label for="security">امنیت</label>
    <select name="security" class="form-control form-control-sm" id="security">
      <option value="0" @if(old('security' ,$file->security) == 0) selected @endif>امنیت فایل آنچنان مهم نیست</option>
      <option value="1" @if(old('security' ,$file->security) == 1) selected @endif>در فضای امن</option>
    </select>
  </div>
  @error('security')
    <span class="alert_required bg-danger text-white p-1 rounded" role="alert">
      <strong>{{ $message }}</strong>
    </span>
  @enderror
</section>

 

controller store:

$inputs['security'] == 0?
    $result = $fileService->moveToPublic($request->file('file')):
    $result = $fileService->moveToStorage($request->file('file'));

 

controller update:

$file->security == 0)?
    $fileService->deleteFile($file->file_path):
    $fileService->deleteFile($file->file_path, true)

$inputs['security'] == 0 ?
    $result = $fileService->moveToPublic($request->file('file')) :
    $result = $fileService->moveToStorage($request->file('file'));

 

در فیلبل ها، ریکوئست ها و دیتابیسش هم تغییرایی داده شد که خب وقتی به این قسمت رسیدیم ینی واضحه

logo-enamadlogo-samandehi