Skip to content

Commit

Permalink
Mehrfach Foto Upload; Bugs gefixed
Browse files Browse the repository at this point in the history
Es ist nun möglich mehrere Fotos gleichzeitig hochzuladen, wird jedoch noch nicht validiert!
  • Loading branch information
Eddcapone committed Feb 25, 2017
1 parent 8ca8df2 commit eacf085
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 99 deletions.
22 changes: 11 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
<ul class="nav navbar-nav Menu">
<li><a href="inserate.html">Inserate</a></li>
<li><a href="verkaufen.html">Verkaufen</a></li>
</ul>
<form class="navbar-form navbar-right Login">
<div class="form-group">
<input type="text" placeholder="Benutzer" class="form-control">
</div>
<div class="form-group">
<input type="password" placeholder="Passwort" class="form-control">
</div>
<button type="submit" class="btn btn-success">Anmelden</button>
<a class="btn btn-success" style="font-size: 20px !important;" data-toggle="modal" data-target="#RegistraturDialog">Registrieren</a>
</form>
</ul>
<form class="navbar-form navbar-right Login">
<div class="form-group">
<input type="text" placeholder="Benutzer" class="form-control">
</div>
<div class="form-group">
<input type="password" placeholder="Passwort" class="form-control">
</div>
<button type="submit" class="btn btn-success">Anmelden</button>
<a class="btn btn-success" style="font-size: 20px !important;" data-toggle="modal" data-target="#RegistraturDialog">Registrieren</a>
</form>
</div>
</div>
</div>
Expand Down
134 changes: 85 additions & 49 deletions shop/app/Http/Controllers/CarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
use Validator;
use Redirect;
use Session;
use Storage;

use App\Car;
use App\Image;

class CarController extends Controller
{
public $imageCounter = 1;

public function show()
{
return view('cars.index');
Expand Down Expand Up @@ -48,6 +51,38 @@ public function showByTitle($title)

return view('car.showByTitle')->with("car", $car);
}

/**
* Filter
*
* @param int $request
* @return \Illuminate\Http\Response
*/
public function filter()
{
$this->validate(request(), [
'price' => 'required|numeric',
'brand' => 'required|alpha',
'model' => 'required|alpha_dash',
]);

if ($this->validate->fails()) {

Session::flash('error', 'uploaded file is not valid');
return Redirect::to('/');

} else {
echo $this->request->price;
die;

$matchingCars = Car::where('model', '=', $this->request->model)->get();
$allImages = Image::all();

return view('cars.showAll')
->with("allCars", $matchingCars)
->with("allImages", $allImages);
}
}

/**
* Display the specified resource.
Expand All @@ -64,75 +99,76 @@ public function showAll()
->with("allImages", $allImages);
}

public function store()
{
/**
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate(request(), [
'title' => 'required|max:80',
'description' => 'required|min:10',
'price' => 'required|numeric',
'brand' => 'required|alpha',
'model' => 'required|alpha_dash',
'image' => 'required|image|dimensions:min_width=100,min_height=200'
'title' => 'required|max:80',
'description' => 'required|min:10',
'price' => 'required|numeric',
'brand' => 'required|alpha',
'model' => 'required|alpha_dash'
]);

$car = new Car();

$car->title = request('title');
$car->description = request('description');
$car->price = request('price');
$car->brand = request('brand');
$car->model = request('model');
$car->title = request('title');
$car->description = request('description');
$car->price = request('price');
$car->brand = request('brand');
$car->model = request('model');

$car->save();

$allCars = Car::all();
$image = $this->upload($car->id);
$allCars = Car::all();
$allImages = $request->file('image');

if(!empty($allImages)):
foreach($allImages as $image):
$image = $this->upload($image, $car->id);
endforeach;
endif;

return redirect('showAll');
return redirect('cars/showAll')
->with("allCars", $allCars)
->with("images", $allImages);
}

public function upload($car_id)

/**
*
* @param integer $car_id
* @return Image
*/
public function upload($image, $car_id)
{
// getting all of the post data
$file = array('image' => Input::file('image'));

// setting up rules
$rules = array('image' => 'required',); //mimes:jpeg,bmp,png and for max size max:10000

// doing the validation, passing post data, rules and the messages
$validator = Validator::make($file, $rules);

if ($validator->fails()) {
// send back to the page with the input data and errors
return Redirect::to('upload')->withInput()->withErrors($validator);

} else {

// checking file is valid.
if (Input::file('image')->isValid()) {
if ($image->isValid()) {

$uploadPath = 'uploads';
// getting image extension
$extension = Input::file('image')->getClientOriginalExtension();
$fileName = date("Ymdis").'.'.$extension;
$extension = $image->getClientOriginalExtension();
$fileName = date("Ymdis").$this->imageCounter++.'.'.$extension;
// uploading file to given path
Input::file('image')->move($uploadPath, $fileName);
$image = new Image();
$image->setCarId($car_id);
$image->setPath( $uploadPath . "/" . $fileName );
$image->save();
$image->move($uploadPath, $fileName);

$ImageObj = new Image();
$ImageObj->setCarId($car_id);
$ImageObj->setPath( $uploadPath . "/" . $fileName );
$ImageObj->save();

Session::flash('success', 'Upload successfully');
return $image;

return $ImageObj;

} else {

// sending back with error message.
Session::flash('error', 'uploaded file is not valid');
return Redirect::to('/');
}
}
}
}
6 changes: 5 additions & 1 deletion shop/public/css/main.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.carObject {
display: inline-block;
border: 2px solid #D8D8D8;
border: 2px solid #ffdbdb;
min-height:400px;
}

Expand Down Expand Up @@ -60,6 +60,10 @@
padding-right: 10px;
}

p.detailsDescription {
margin-bottom: 0px;
}

table.details tr td {

min-width: 80px;
Expand Down
56 changes: 37 additions & 19 deletions shop/resources/views/cars/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,66 @@

@section('content')

{!! Form::open(array('action' => 'CarController@store', 'files'=>true)) !!}
<form id="store" class="marginTop" method="POST" action="store" enctype="multipart/form-data">

{{ csrf_field() }}

@if(Session::has('error'))
<p class="errors">{!! Session::get('error') !!}</p>
@endif

<div class="form-group">
<label for="title" class="control-label">Titel</label>
<input type="text" class="form-control" id="title" name="title">
<input type="text" class="form-control" id="title" name="title" value="">
</div>
<div class="form-group">
<label for="description" class="control-label">Beschreibung</label>
<textarea class="form-control" id="description" name="description"></textarea>
<textarea class="form-control" id="description" name="description" ></textarea>
</div>
<div class="form-group">
<label for="price" class="control-label">Preis</label>
<input type="text" class="form-control" id="price" name="price">
<input type="text" class="form-control" id="price" name="price" value="">
</div>
<div class="form-group">
<label for="brand" class="control-label">Marke</label>
<input type="text" class="form-control" id="brand" name="brand">
<input type="text" class="form-control" id="brand" name="brand" value="">
</div>
<div class="form-group">
{!! Form::label('model','Modell',array('id'=>'model','class'=>'')) !!}
{!! Form::text('model','',array('id'=>'model','class'=>'', 'placeholder' => 'model')) !!}
<label for="model" class="control-label">Model</label>
<input type="text" class="form-control" id="model" name="model" value="">
</div>
<br>
<div class="form-group">
{!! Form::label('Bild') !!}
{!! Form::file('image', null) !!}

<p class="errors">{!!$errors->first('image')!!}</p>

@if(Session::has('error'))
<p class="errors">{!! Session::get('error') !!}</p>
@endif
<input type="file" name="image[]" multiple>
</div>



<div class="form-group">
{!! Form::submit('Senden') !!}
<button type="submit" class="btn btn-default">Senden</button>
</div>

@include('layouts.partials.errors')

{!! Form::close() !!}
</form>

<script>
var form = document.getElementById('store');
var request = new XMLHttpRequest();
form.addEventListener('submit', function(e)
{
e.preventDefault();
var formdata = new FormData(form);
request.open('post', 'store');
request.addEventListener('load', transferComplete);
request.send(formdata);
});
function transferComplete(data){
document.write(data.currentTarget.response);
}
</script>

@endsection
4 changes: 1 addition & 3 deletions shop/resources/views/cars/showAll.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
@foreach($allImages as $image)
@if ($car->id === $image->car_id)

<a href="/nenc-auto-shop/shop/public/{{ $image->path }}">
<!--<img src="{{ $image->path }}" id="picture_{{ $image->id }}" class="image" alt="{{ $image->path }}">-->
</a>
<a href="/nenc-auto-shop/shop/public/{{ $image->path }}"></a>

@endif
@endforeach
Expand Down
13 changes: 11 additions & 2 deletions shop/resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
@section('content')

<div onClick="closeNav();" class="container FilterContainer">
<form class="form-inline marginTop">
<table class="FilterTable">

<form class="form-inline marginTop" method="POST" action="filter" id="filter">

{{ csrf_field() }}

@if(Session::has('error'))
<p class="errors">{!! Session::get('error') !!}</p>
@endif

<table class="FilterTable">
<tr>
<td>
<div class="form-group">
Expand Down Expand Up @@ -33,4 +41,5 @@
</table>
</form>
</div>

@stop
16 changes: 8 additions & 8 deletions shop/resources/views/layouts/partials/errors.blade.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@if(count($errors))
<div class="form-group">
<div class="alert alert-danger" role="alert">
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
<div class="form-group">
<div class="alert alert-danger" role="alert">
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
</div>
</div>
@endif
11 changes: 5 additions & 6 deletions shop/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
|
*/

Route::get('/', function () { return view('welcome'); });
Route::get('/', function () { return view('welcome'); });
Route::get('home', function () { return view('home'); });

//Route::get('/cars', 'CarController@show');
Route::get('cars/create', 'CarController@create');
Route::get('cars/showAll', 'CarController@showAll');
Route::post('cars/filter', 'CarController@filter');
Route::post('cars/store', 'CarController@store');
Route::get('cars/create', 'CarController@create');
Route::get('cars/showAll', 'CarController@showAll');
Route::post('cars/filter', 'CarController@filter');
Route::post('cars/store', 'CarController@store');

/*--Footer--------------------------------------*/
Route::get('impressum', function () { return view('footer.impressum'); });
Expand Down

0 comments on commit eacf085

Please sign in to comment.