Cara Membuat agar bisa upload file banyak dengan 2 File Input

Saya akan membuat beberapa file unggahan dengan 2 file input tetapi saya tidak tahu
Fields.blade.php

<div class="form-group col-sm-6" id="cover">
 {!! Form::label('cover', 'Cover:') !!}
 {!! Form::file('cover', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-sm-6" id="full">
 {!! Form::label('full', 'Full:') !!}
 {!! Form::file('full', null, ['class' => 'form-control']) !!}
</div>

CatalogController.php

public function createWithCategory($id)
    {
        $katalog_metadata = \App\Models\KatalogMetadata::with('metadata')
        ->where('category_id',$id)->get();
        return view('catalogs.create')
        ->with('katalog_metadata',$katalog_metadata)
        ->with('category_id',$id);
    }
public function store(CreateCatalogRequest $request)
    {
        $input = $request->all();
        if (\Auth::user()->can('isAdmin')) {
            $input['status'] = 1 ;
        }else{
            $input['status'] = 0 ;
        }
$input['cover'] = $this->uploadingCover($request);
$input['full'] = $this->uploadingFull($request);
$catalog = $this->catalogRepository->create($input);
foreach ($input['metadata'] as $key => $value) {
         $val = [
            'metadata_id'=>$key,
            'metadata_key'=>$value['key'],
            'value'=>$value['value'],
            'catalog_id'=>$catalog->id
           ];
$data = new \App\Models\CatalogMetadataValue($val);       
$catalog->catalog_metadata_value()->save($data);
        }
if (! \Auth::user()->can('isAdmin')) {
            $admin = \App\Models\User::where('role_id','1')->first();
            Mail::to($admin->email)->send(new NotifyNewCatalog($catalog));
        } 
Flash::success('Catalog saved successfully.');
return redirect(route('catalogs.index_with_category',$request->category_id));
    }`protected function uploadingCover($request)
    {
       $destinationPath = 'catalog/cover';
       if(! is_dir($destinationPath)) {
       if(! is_dir('catalog')){
             mkdir('catalog');
            }
        mkdir($destinationPath);
        }
if($request->hasFile('cover')) {
   $file = $request->file('cover');
   $fileName = time() . '.' .$file->getClientOriginalExtension();
   $file->move($destinationPath, $fileName);
 return $destinationPath . '/' . $fileName;
        }
return;
    }
protected function uploadingFull($request){
    $destinationPath = 'catalog/full';
    if(! is_dir($destinationPath)) {
      if(! is_dir('catalog')){
        mkdir('catalog');}
        mkdir($destinationPath);}
    if($request->hasFile('full')) {
       $file = $request->file('full');
       $fileName = time() . '.' . $file->getClientOriginalExtension();
       $file->move($destinationPath, $fileName);
     return $destinationPath . '/' . $fileName;
    }
    return;
    }`
avatar marfino3028

Ditanyakan oleh @marfino3028

3 Kontribusi 0 Poin

Login untuk menanggapi


Jawaban

multiple kali gan maksudny? jadi bisa masukin banyak file dalam 1 form?
avatar werich1

Dijawab oleh @werich1

85 Kontribusi 6 Poin

Login untuk menanggapi


Login untuk gabung berdiskusi