validate uploading image on laravel 4 - php

I'm new to Laravel. I have a form with a File upload function on it. How can I validate image file? . when i execute my code the images are getting uploaded but URL is not saved to the MySQL database, and it shows validation errors on the form as follows.
The thumbnail must be an image.
The large image must be an image.
Here's my input and validation code .
{{ Form::open(array('url' => 'admin/templates/save', 'files' => true, 'method' => 'post')) }}
#if($errors->has())
#foreach($errors->all() as $error)
<div data-alert class="alert-box warning round">
{{$error}}
×
</div>
#endforeach
#endif
<div class="row">
<div class="small-5 large-5 column">
{{ Form::label('title','Title:') }}
{{ Form::text('title',Input::old('title')) }}
</div>
</div>
<div class="row">
<div class="small-7 large-7 column">
{{ Form::label('description','Description:') }}
{{ Form::textarea('description',Input::old('description'),['rows'=>5]) }}
</div>
</div>
<div class="row">
<div class="small-7 large-7 column">
{{ Form::label('detailed_description','Detailed description:') }}
{{ Form::textarea('detailed_description',Input::old('detailed_description'),['rows'=>5]) }}
</div>
</div>
<div class="row">
<div class="small-5 large-5 column">
{{ Form::label('thumbnail','Choose thumbnail image:') }}
{{ Form::file('thumbnail') }}
</div>
</div>
<div class="row">
<div class="small-5 large-5 column">
{{ Form::label('large_image','Choose large image:') }}
{{ Form::file('large_image') }}
</div>
</div>
<div class="row">
<div class="small-5 large-5 column">
{{ Form::label('targeturl','Target URL:') }}
{{ Form::text('targeturl',Input::old('Target URL')) }}
</div>
</div>
{{ Form::submit('Save',['class'=>'button tiny radius']) }}
{{ Form::close() }}
Controller code
<?php
class TemplateController extends BaseController
{
public function newTemplate()
{
$this->layout->title = 'New Template';
$this->layout->main = View::make('dash')->nest('content', 'templates.new');
}
public function saveTemplate() {
//TODO - Validation
$destinationPath = '';
$filename = '';
$destinationThumb = '';
$thumbname = '';
$thumb = Input::file('thumbnail');
$destinationThumb = public_path().'/thumb/';
$thumbname = str_random(6) . '_' . $thumb->getClientOriginalName();
$uploadSuccess = $thumb->move($destinationThumb, $thumbname);
$file = Input::file('large_image');
$destinationPath = public_path().'/img/';
$filename = str_random(6) . '_' . $file->getClientOriginalName();
$uploadSuccess = $file->move($destinationPath, $filename);
$rules = [
'title' => 'required',
'description' => 'required',
'detailed_description' => 'required',
'targeturl' => 'required',
'thumbnail' => 'required|image',
'large_image' => 'required|image'
];
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes()) {
$template = new Template();
$template->title = Input::get('title');
$template->description = Input::get('description');
$template->thunbnailURL = $destinationThumb . $thumbname;
$template->detailedDescription = Input::get('detailed_description');
$template->targetURL = Input::get('targeturl');
$template->detailImageURL = $destinationPath . $filename;
//$user->created_at = DB::raw('NOW()');
//$user->updated_at = DB::raw('NOW()');
$template->save();
return Redirect::back()->with('success', 'Template added!');
} else
return Redirect::back()->withErrors($validator)->withInput();
}
}
Please help me.

Move your upload code inside validation passes
public function saveTemplate() {
//TODO - Validation
$rules = [
'title' => 'required',
'description' => 'required',
'detailed_description' => 'required',
'targeturl' => 'required',
'thumbnail' => 'required|image',
'large_image' => 'required|image'
];
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes()) {
$thumb = Input::file('thumbnail');
$destinationThumb = public_path().'/thumb/';
$thumbname = str_random(6) . '_' . $thumb->getClientOriginalName();
$uploadSuccess = $thumb->move($destinationThumb, $thumbname);
$file = Input::file('large_image');
$destinationPath = public_path().'/img/';
$filename = str_random(6) . '_' . $file->getClientOriginalName();
$uploadSuccess = $file->move($destinationPath, $filename);
$template = new Template();
$template->title = Input::get('title');
$template->description = Input::get('description');
$template->thunbnailURL = $destinationThumb . $thumbname;
$template->detailedDescription = Input::get('detailed_description');
$template->targetURL = Input::get('targeturl');
$template->detailImageURL = $destinationPath . $filename;
//$user->created_at = DB::raw('NOW()');
//$user->updated_at = DB::raw('NOW()');
$template->save();
return Redirect::back()->with('success', 'Template added!');
} else
return Redirect::back()->withErrors($validator)->withInput();
}

Related

I'm getting strange error Method Illuminate\Http\UploadedFile::backup does not exist

I'm trying on Laravel with "Intervention image" package to resize uploaded image 2x times with different resolution. That why i used backup() method to store original resolution of picture before process of resizing is made. But when i run my code I'm getting the error "Method Illuminate\Http\UploadedFile::backup does not exist." Does anyone knows where is a problem ?
Create.blade.php
#extends('layout')
#section('content')
<div class="container2">
<div class="container">
<div class="card card-container">
<!-- <img class="profile-img-card" src="//lh3.googleusercontent.com/-6V8xOA6M7BA/AAAAAAAAAAI/AAAAAAAAAAA/rzlHcD0KYwo/photo.jpg?sz=120" alt="" /> -->
<h1 style="text-align: center;">Napiši Vijest</h1>
#if(count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach($errors ->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
#endif
{!! Form::open(['action' => 'MainController#store', 'method' => 'POST', 'files' => true]) !!}
<div class="form-group">
{{Form::label('postName', 'Ime')}}
{{Form::text('postName', '', ['id' => 'postName', 'class' => ($errors->has('postName')) ? 'form-control is-invalid' : 'form-control', 'placeholder' => 'Unesite naslov'])}}
</div>
<div class="form-group">
{{Form::label('naslov', 'Naslov')}}
{{Form::text('naslov', '', ['id' => 'inputname', 'class' => ($errors->has('naslov')) ? 'form-control is-invalid' : 'form-control', 'placeholder' => 'Unesite naslov'])}}
</div>
<div class="form-group">
{{Form::label('sadržaj', 'Sadržaj')}}
{{Form::textarea('sadržaj', '', ['id' => 'inputtext', 'class' => ($errors->has('sadržaj')) ? 'form-control is-invalid' : 'form-control', 'placeholder' => 'Unesite sadržaj'])}}
</div>
<div class="form-group">
{{Form::label('file', 'Izaberi fajl')}}
{{ Form::file('file') }}
</div>
<div class="form-group">
{{Form::label('slika', 'Izaberi sliku')}}
{{Form::file('slika')}}
</div>
<div class="form-group">
{{Form::label('Category', 'Izaberi kategoriju')}}
{{Form::select('category', $category, null) }}
</div>
{{Form::submit('Prihvati', ['class' => 'btn btn-success']) }}
Početna strana
{!! Form::close() !!}
</div><!-- /card-container -->
</div><!-- /container -->
</div><!-- /container -->
#endsection
Web.php
Route::get('/createPost', 'MainController#create')->name('post.create')->middleware('admin');
Controller.php
<?php
namespace App\Http\Controllers;
use Auth;
use Illuminate\Http\Request;
use App\Http\Request2;
//including post model to controller
use validate;
use App\Post;
use App\Document;
use App\Category;
//if we want to use sql syntax for queries
use DB;
use File;
use Image;
use Mail;
use Session;
USE Validator;
use Redirect;
use Illuminate\Support\Facades\Input;
class MainController extends Controller
{
public function create()
{
$category = Category::pluck('title', 'id');
return View('create', compact('category',$category));
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$rules = [
'naslov' => 'required|min:3|max:20',
'sadržaj' => 'required|min:40',
'slika' => 'mimes:jpeg,bmp,png'
];
$customMessages = [
'required' => 'Unesite ":attribute" !',
'min' => 'Polje ":attribute" mora da ima minimum :min karaktera.',
'max' => 'Polje ":attribute" može da ima najviše :max karaktera.',
'email' => 'Polje ":attribute" mora da ima validan format',
'mimes' => '":attribute" mora biti u sledećim formatima: :values'
];
$validator = Validator::make(Input::all(), $rules, $customMessages);
if ($validator->fails())
{
return \Redirect::back()->withErrors($validator)->withInput();
}
//create new post
$post= new Post;
$post -> name = $request -> input('postName');
$post -> title = $request -> input('naslov');
$post -> content = $request -> input('sadržaj');
$post -> category_id = $request -> input('category');
// Handle File Upload
if( $request->hasFile('file') ) {
$filenameWithExt = $request->file('file')->getClientOriginalName();
// Get just filename
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
// Get just ext
$extension = $request->file('file')->getClientOriginalExtension();
// Filename to store
$fileNameToStore= $filename.'_'.time().'.'.$extension;
// Upload Image
$path = $request->file('file')->storeAs('public/upload', $fileNameToStore);
$post->file_name = $fileNameToStore;
}
// Check if file is present
if( $request->hasFile('slika') ) {
$post_thumbnail = $request->file('slika');
$filename = time() . '.' . $post_thumbnail->getClientOriginalExtension();
$post_thumbnail->backup();
ini_set('memory_limit', '256M');
$filename=Image::make($post_thumbnail);
$filename->resize(329.33, 199.33)->save( public_path('uploads/' . $filename ) );
$post->post_thumbnail = $filename;
}
$post->save();
return redirect()->route('posts.show', $post)->with('successPost', 'Napisali ste novu vijest !');
}
}
You can do that,
//$post_thumbnail = Image::make($request->file('slika'));
// $post_thumbnail->backup();
$post_thumbnail = $request->file('slika');
$filename = time() . '.' . $post_thumbnail->getClientOriginalExtension();
Image::make($post_thumbnail)->backup();
ini_set('memory_limit', '256M');
// $filename=Image::make($post_thumbnail);

Preloading image in edit form

I have edit form which is populated from database when I go to update page. Everything works fine except the image part. If I don't submit new image it deletes old one too.
This is my controller
public function update( ItemRequest $request){
$item = Item::find( $request['id'] );
$filename=null;
$image = $request->file('image');
if($request->hasFile('image'))
{
if($image->isValid()){
$extension = $image->getClientOriginalExtension();
$uploadPath = public_path(). '/uploads';
$filename = rand(111,999). '.'. $extension;
$image->move($uploadPath, $filename);
}
}
$item->title = $request['title'];
$item->category_id = $request['category_id'];
$item->price = $request['price'];
$item->description = $request['description'];
$item->image = $filename? $filename: $item->image;
$item->image = $filename;
if($item->save()){
if(!is_null($filename)){
$item_image = new Item_Images;
$item_image->image = $filename;
$item_image->item_id = $item->id;
$item_image->published = 1;
$item_image->save();
}
$request->session()->flash('alert-success','Item updated successfully.');
} else
$request->session()->flash('alert-error','Can not update item now. Plese tyr again!!.');
return redirect()->route('products');
}
And the corresponded fields for image on the form
#if( $item['image'] )
<div class="form-group">
{!! Form::label('inputImage', 'Existing Image', array('class'=> 'col-sm-2 control-label')) !!}
<div class="col-sm-10">
<img src="{!!asset('/uploads/'. $item['image'] )!!}" />
</div>
</div>
#endif
<div class="form-group">
{!! Form::label('inputImage', 'Image', array('class'=> 'col-sm-2 control-label')) !!}
<div class="col-sm-10">
{!! Form::file('image', ['class'=>'form-control', 'id'=>'inputImage']) !!}
</div>
</div>
First I check if there is image in database and if there is it is shown on the page. There there is the file field.
So is it possible to load as a value the current image in file field of form? Or this must be done in controller logic somehow?
Remove this line to fix the problem:
$item->image = $filename;
By doing this, you'll set image as null if no image was uploaded.

Call to undefined method Illuminate\Http\Request::angel.jpg()

I have a form, I have troubles in Upload an Image :(
I am trying to upload some image and I don't know what I am doing bad :(
{{ Form::open (['route' => 'titulos.store', 'class'=> 'form', 'files'=> 'true']) }}
{{ Form::label('title', "Titulo:", ['class' => 'col-sm-2 control-label']) }}
{{ Form::text('title') }}
{{ $errors->first('title') }}
<div class="form-group">
{{ Form::label('date', "Fecha:", ['class' => 'col-sm-2 control-label']) }}
<input type="date" name="date" >
</div>
{{ Form::label('description', "Description:", ['class' => 'col-sm-2 control-label']) }}
{{ Form::textarea('description') }}
{{ $errors->first('description') }}
<div class="form-group">
{{ Form::file('image') }}
</div>
{{ Form::label('category_id', 'Category:', ['class' => 'col-sm-2 control-label']) }}
<div class="col-sm-10">
{{ Form::select('category_id', array('1' => 'TBLeaks', '2' => 'Quejas', '3' => 'Denuncias', '4' => 'Ideas'), null, array('class' => 'form-control')) }}
</div>
<div class="row">
<div class="col-sm-offset-2 col-sm-10">
{{ Form::submit('Submit', ['class' => "btn btn-primary"]) }}
</div>
</div>
<div class="row">
<div class="col-sm-offset-2 col-sm-10">
<a class="btn btn-success" href="{{ URL::to('admin') }}">Back to Admin</a>
</div>
</div>
{{ Form::close() }}
</div>
#if(Session::has('message'))
<div class="alert alert-{{ Session::get('class') }}">{{ Session::get('message')}}</div>
#endif
#stop
In my store function I have:
class TitulosController extends BaseController {
public function store(){
$rules = array(
'title' => 'required',
'description' => 'required',
'category_id' => 'required'
);
$validator = Validator::make(Input::all(), $rules);
// proceso de valicion
if ($validator->fails()) {
return Redirect::to('titulos/create')
->withErrors($validator)
->withInput()->withErrors($validator);
} else {
//store
$image = Input::file('image');
$filename = $image->getClientOriginalName();
if(Input::hasFile('image')){
Input::file('image')->move(public_path().'/assets/img/', $filename);
}
$titulo = new Titulo();
$titulo->id = Input::get('id');
$titulo->title = Input::get('title');
$titulo->description = Input::get('description');
$titulo->date = Input::get('date');
$titulo->image = Input::$filename('image');
$titulo->category_id = Input::get('category_id');
$titulo->save();
return Redirect::to('titulos');
}
I have this model for the Titulo table:
class Titulo extends Eloquent {
use SoftDeletingTrait; // for soft delete
protected $dates = ['deleted_at']; // for soft delete
protected $table = 'titulos';
protected $primaryKey = 'id';
protected $fillable = array('image');
public $timestamps = true;
public function __construct() {
parent::__construct();
}
public function category(){
return $this->belongsTo('Category');
}
}
I have this for Image model:
class Image extends Eloquent {
public $timestamps = false;
protected $fillable = array('image');
}
At this line where your store to public path should be no problem
if(Input::hasFile('image')){
Input::file('image')->move(public_path().'/assets/img/', $filename);
}
Only your save Tutilo object looks not good. I think you have mistakenly add $ on Input::filename at this line. which will call the image
$titulo->image = Input::$filename('image');
change your code to this
$titulo = new Titulo();
$titulo->id = Input::get('id');
$titulo->title = Input::get('title');
$titulo->description = Input::get('description');
$titulo->date = Input::get('date');
$titulo->image = $filename; // I change this line. assuming you want to store the file name
$titulo->category_id = Input::get('category_id');

How to submit files in Laravel

My form is as follow
{{ Form::open(array( 'enctype' => 'multipart/form-data'))}}
<div class="vendor-box-wrap">
<div class="page3-suggested-cat-wrap" style="float: left;width: 100%;border-bottom: 1px dotted;padding-bottom: 10px;margin-left: 20px;">
<label style="width:9%;" for="9009" class="page3-suggested-cat-label" >BoQ</label>
<div class="input-group" style="margin-top: 10px;
width: 70%;">
<span class="form-control"></span>
<span class="input-group-btn">
<span class="btn btn-primary" onclick="$(this).parent().find('input[type=file]').click();">Browse</span>
<input name="file|90009|107" id="file|9009"
value="" onchange="$(this).parent().parent().find('.form-control').html($(this).val().split(/[\\|/]/).pop());"
style="display: none;" type="file">
</span>
</div>
</br> <center><h2><strong>OR</strong></h2></center>
</div>
</div>
<div class="next-btn-wrap"><div class="cf"></div>
<div class="back-btn-wrap">
{{ Form::submit('Back',array('class' => 'back-btn', 'name' => 'back'))}}
</div>
<div class="save-btn-wrap">
{{ Form::submit('Save',array('class' => 'save-btn','name' => 'save'))}}
</div>
{{ Form::submit('Next',array('class' => 'next-btn','name' => 'next'))}}
</div>
{{ Form::close()}}
and in my controller I am using following code to get the data
$aa = Input::except(array('_token','back','save','next'));
//dd($aa);
foreach ($aa as $key=>$value){
$ids = explode("|",$key);
if(isset($ids[0]) && $ids[0]=="file" ){
$userid = Session::get('userid');
$event = Session::get('event');
$fileTblObj = new fileHandler();
$ans = Answer::find($ids[2]);
if(isset($aa[$key])){
//dd($aa[$key]);
if(Input::file($key)->isValid()) {
$destinationPath = 'app/uploads/'.$event.'/'.$userid.'/'.$pageNo ; // upload path
$extension = Input::file($key)->getClientOriginalExtension(); // getting image extension
$name = Input::file($key)->getClientOriginalName();
$curFilesize = Input::file($key)->getClientSize();
$mime =Input::file($key)->getMimeType();
if (!File::exists($destinationPath."/boq-".$name)){
//creating details for saving inthe file_handler Table
$fileTblObj->user_id = $userid;
$fileTblObj->eventName = $event ;
$fileTblObj->fileName = "boq-".$name;
$fileTblObj->formPage =$pageNo ;
$fileTblObj->filePath = $destinationPath."/";
$fileTblObj->mime= $mime;
$ans->answer_text = 'Yes';
Input::file($key)->move($destinationPath, "boq-".$name); // uploading file to given path
//Input::file($key)->move($boqPath, $boqname); // uploading file to given path
//Save filedetails
$fileTblObj->save();
$ans->save();
Session::flash('success', 'Upload successfully');
}else if(File::size($destinationPath."/".$name) != $curFilesize){
$fileDtls = $fileTblObj->where('uid',$userid)->where('fileName',$name)->where('formPage',$pageNo)->first();
Input::file($key)->move($destinationPath, $name);
$ans->answer_text = 'Yes';
$ans->save();
$fileTblObj->where('id',$fileDtls->id)->update(array('updated_at'=>date("Y-m-d h:m:s",time())));
}
//return Redirect::to('upload');
}
}
else
{
if($ans->answer_text =='')
{
$ans->answer_text = 'No';
$ans->save();
}
}
}
My problem is I am not able to get the file details on the back-end
the if statement
if(isset($ids[0]) && $ids[0]=="file" ){
}
is always false .
Any Idea How I can fix this. I also tried changing the The FOrm function to
{{ Form::open(array('files' => true)) }}
Still its not showing the file details
To send a file, I personally use this methods.
View:
{!! Form::open(array('action' => 'TestController#store', 'method' => 'POST', 'files'=>true)) !!}
{!! Form::file('thefile') !!}
{!! Form::submit('Save', array('class' => 'btn')) !!}
{!! Form::close() !!}
Controller:
$thefile = Input::file('thefile');
Hope this helps!

File upload does not validate correctly in Laravel

I've implemented an option for uploading pictures of employees. It is optional. However, if I try to upload a file that is not valid, it just seems to skip to the show-method, which first of all does not exist, and secondly is never called.
If I edit the form without a file, everything works fine, and the validation also works. If I upload a valid file, it works aswell.
I just don't get why this is happening
Controller:
`public function update($id){
// get the POST data
$new = Input::all();
// get the user
$u = User::find($id);
$picturevalid = true;
if (Input::get('slett') === 'slett') {
$del = $u->employeePicture;
$del->forceDelete();
}
if(Input::hasFile('picture')) {
if ($u->employeePicture) {
$e = $u->employeePicture;
}
else { $e = new Employeepicture(); }
$image = array(Input::file('picture'));
$picturevalid= $e->validate($image);
}
$new['password'] = $u->password;
// attempt validation
if ($u->validate($new, $u->uid) && $picturevalid && (Input::get('groups') || $new['usertype'] == 2))
{
if (Input::hasFile('picture')) {
$imagein = Input::file('picture');
$kid = Session::get('kid');
$uid = $u->uid;
// We should make an url-friendly version of the file
$newname = $uid.'_'.$u->lastname.'_'.$u->firstname.'.'. // newname:kindergarden+kidnr
$imagein->getClientOriginalExtension(); // punktum + filendelse
$thumb_w = 250; // thumbnail size (area cropped in middle of image)
$thumb_h = 300; // thumbnail size (area cropped in middle of image)
$this->resize_then_crop($imagein,$newname,$thumb_w,$thumb_h,/*rgb*/"255","255","255");
//url to be stored in the database
$urlpath = '/Hovedprosjekt/app/storage/upload/'.$kid.'/images/thumbs/';
$url = $urlpath.$newname;
$e->uid = $uid;
$e->url = $url;
$e->updated_at = date('Y-m-d H:i:s');
if(!$e->save())
{
//save unsuccessful
return Redirect::to('employee/'.$id.'/edit')
->with('register_message', 'Endring feilet.');
}
}
$u->firstname = $new['firstname'];
$u->lastname = $new['lastname'];
$u->phone = $new['phone'];
$u->address = $new['address'];
$u->email = $new['email'];
$u->zipcode = $new['zipcode'];
$u->updated_at = date('Y-m-d H:i:s');
$usertype = Usertype::find($new['utid']);
$u = $usertype->user()->save($u);
//saves user to db
if($u->save())
{
if($new['utid'] == 2){
//Styrer
$kid = Session::get('kid');
$kindergarden = Kindergarden::find($kid);
$u->group()->sync(array($kindergarden->leaderGroup()->gid));
}
else {
$groups = Input::get('groups');
if(is_array($groups))
{
$u->group()->sync($groups);
}
}
return Redirect::to('employee')
->with('message', 'Ansatt endret!');
}
else
{
//save unsuccessful
return Redirect::to('employee/' . $id . '/edit')
->with('register_message', 'Endring feilet.');
}
}
else
{
//validation unsuccessful
//Get validadtion errors
$errors = $u->errors();
if(Input::hasFile('picture')) {
$perrors = $e->errors();
if(isset($perrors)){
foreach($perrors->all() as $perror){
$errors->add($perror);
}
}
}
return Redirect::to('employee/'.$id.'/edit')
->withErrors($errors) // send back all errors to the login form
->withInput(Input::all()); // send back the input (not the password) so that we can repopulate the form
}
}`
Models:
Employeepicture.php
`private $rules = array(
'picture' => 'mimes:jpg,png,gif'
);
private $errors;
/**
* Validation method
*
* #return boolean
*/
public function validate($data) {
// make a new validator object
$v = Validator::make($data, $this->rules);
// check for failure
if ($v->fails()) { // set errors and return false
$this->errors = $v->errors();
return false;
}
// validation pass
return true;
}`
User.php
`private $rules = array(
'firstname' => 'required|max:40',
'lastname' => 'required|max:40',
'email' => 'required|email|unique:user', // make sure the email is an actual email
'phone' => 'required|numeric|digits_between:7,20',
'address' => 'required|min:3',
'picture' => 'mimes:jpg,jpeg,png,gif|max:2046',
'zipcode' => 'required|numeric|digits_between:1,4'
//'password' => 'required|min:3',
//'password_confirmation' => 'same:password'//required?
);
/**
* Valditation errors
*/
private $errors;
/**
* Validation method
*
* #return boolean
*/
public function validate($data, $update)
{
if (isset($update)) {
$this->rules['email'] = 'required|email|unique:user,email,' . $update . ',uid';
}
// make a new validator object
$v = Validator::make($data, $this->rules);
// check for failure
if ($v->fails())
{
// set errors and return false
$this->errors = $v->errors();
return false;
}
// validation pass
return true;
}
/**
* Validation errors
*/
public function errors()
{
return $this->errors;
}`
The edit view:
`#extends('employee.employeelayout')
#section('title', 'Endre ansatt')
#section('employeecontent')
<h3>Endre ansatt</h3>
#if (Session::has('register_message'))
<div id="register_message"><p>{{ Session::get('register_message') }}</p></div>
#endif
<ul>
#foreach($errors->all() as $error)
<li>{{ str_replace($eng, $nor, $error) }}</li>
#endforeach
</ul>
{{ Form::model($employee, array('route' => array('employee.update', $employee->uid), 'method' => 'PUT', 'files'=>true)) }}
<div class="form-group">
{{ Form::label('firstname', 'Fornavn', array('class'=>'control-label')) }}
{{ Form::text('firstname', null, array('class'=>'form-control', 'placeholder'=>'Fornavn')) }}
</div>
<div class="form-group">
{{ Form::label('lastname', 'Etternavn', array('class'=>'control-label')) }}
{{ Form::text('lastname', null, array('class'=>'form-control', 'placeholder'=>'Etternavn')) }}
</div>
<div class="form-group">
{{ Form::label('email', 'E-post', array('class'=>'control-label')) }}
{{ Form::text('email', null, array('class'=>'form-control', 'placeholder'=>'E-post')) }}
</div>
<div class="form-group">
{{ Form::label('phone', 'Telefonnummer', array('class'=>'control-label')) }}
{{ Form::text('phone', null, array('class'=>'form-control', 'placeholder'=>'Telefonnummer')) }}
</div>
<div class="form-group">
{{ Form::label('address', 'Adresse', array('class'=>'control-label')) }}
{{ Form::text('address', null, array('class'=>'form-control', 'placeholder'=>'Adresse')) }}
</div>
<div class="form-group">
{{ Form::text('zipcode', null, array('class'=>'form-control', 'placeholder'=>'Postnummer')) }}
</div>
<div class="form-group">
{{ Form::label('image', 'Bilde av ansatt(valgfritt): ') }}
{{ Form::file('picture', null, array('class'=>'input-block-level', 'placeholder'=>'Picture')) }}
#if($employee->employeePicture)
<h5>Nåværende bilde</h5>
<img class="small-pic" src="{{$employee->employeePicture->url}}"/><br>
{{ Form::checkbox('slett', 'slett'); }} Fjern
#endif
</div>
<div class="form-group">
{{ Form::label('utid', 'Brukertype', array('class'=>'control-label')) }}
{{ Form::select('utid', $usertypes, $employee->utid, array('class'=>'form-control','id'=>"select_usertype")) }}
</div>
<div class="form-group" id="group">
{{ Form::label('group', 'Avdeling', array('class'=>'control-label')) }}
#foreach($groups as $group)
#if ($employee->group->contains($group->gid))
<div class='checkbox'>{{ Form::checkbox('groups[]', $group->gid, true) }} {{ $group->name }}</div>
#else
<div class='checkbox'>{{ Form::checkbox('groups[]', $group->gid) }} {{ $group->name }}</div>
#endif
#endforeach
</div>
<div class="pull-right">
{{ Form::submit('Endre', array('class'=>'btn btn-primary'))}}
</div>
{{ Form::close() }}
<a class="btn btn-primary" href="{{ URL::to('employee') }}"><span class="glyphicon glyphicon-arrow-left"></span> Tilbake</a>`

Categories