Skip to content

Instantly share code, notes, and snippets.

@ibahas
Created November 1, 2019 13:44
Show Gist options
  • Save ibahas/c31da381889c51006fe379b5d5744287 to your computer and use it in GitHub Desktop.
Save ibahas/c31da381889c51006fe379b5d5744287 to your computer and use it in GitHub Desktop.
Problem in my controller to upload multiple images and save in database .
<?php
namespace App\Http\Controllers;
use App\album;
use Illuminate\Http\File;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class AlbumController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
$data = album::all();
return view('control.album.index', compact('data'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
return view('control.album.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(request $request)
{
request()->validate([
'album' => 'mimes:jpg,jpeg,png,gif|max:2048',
]);
$input=$request->all();
$images=array();
if($files=$request->file('album')){
foreach($files as $item){
$name=$item->getClientOriginalName();
$item->move('album',$name);
$images[]=$name;
}
}
/*Insert your data*/
$ndate=date('Y-m-d H:i:s');
echo $imgfile;
$data=[
'title_album'=>$request->title_album,
'description_album'=>$request->description_album,
'ndate'=>$ndate,
'img'=>$images
];
album::create($data);
return redirect("newspost");
return redirect("album");
}
/**
* Display the specified resource.
*
* @param \App\album $album
* @return \Illuminate\Http\Response
*/
public function show(album $album)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\album $album
* @return \Illuminate\Http\Response
*/
public function edit(album $album)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\album $album
* @return \Illuminate\Http\Response
*/
public function update(Request $request, album $album)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\album $album
* @return \Illuminate\Http\Response
*/
public function destroy(album $album)
{
//
}
}
in my veiw ...
@extends('layout.cp.control1')
@section('main')
<!-- Page Heading -->
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
</div>
<div class="card-body">
<div class="table-responsive">
<form method="post" action="{{ Route('album.store') }}" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="title_album">Title</label>
<input type="text" class="form-control" id="title_album" name="title_album" aria-describedby="title_album" >
</div>
<div class="form-group">
<label for="description_album">description</label>
<textarea class="form-control rounded-0" id="description_album" name="description_album" rows="3"></textarea>
</div>
<div class="form-group">
<div class="file-field">
<div class="btn btn-primary btn-sm float-left">
<input required type="file" name="images[]" multiple>
</div>
<br/>
</div>
</div>
<div class="form-group col-md-12 text-center">
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</div>
</div>
</div>
@endsection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment