issue with file uploading in laravel - php

I am try to upload a file with laravel but when submit the form it gives the below error
Exception
Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed
here is my blade:
{{ Form::open(array('route' => 'drivers.store', 'files' => true, 'class' => 'form-horizontal')) }}
<form role="form">
<div class="form-group first-field">
{{ Form::label('first_name', 'First Name:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4 ">
{{ Form::text('first_name', $value = null, array('placeholder' => 'ex-Jon', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('first_name') }} </span>
<div class="form-group">
{{ Form::label('last_name', 'Last Name:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('last_name', $value = null, array('placeholder' => 'ex-Doe', 'required' => 'required', 'class' => 'form-control', 'class' => 'form-control')) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('last_name') }} </span>
<div class="form-group">
{{ Form::label('email', 'Email:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('email', $value = null, array('placeholder' => 'ex-test#example.com', 'rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('email') }} </span>
<div class="form-group">
{{ Form::label('contact_number', 'Phone:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('contact_number', $value = null, array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('contact_number') }} </span>
<div class="form-group">
{{ Form::label('sin', 'SIN:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('sin', $value = null, array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('sin') }} </span>
<div class="form-group">
{{ Form::label('license_number', 'License Number:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('license_number', $value = null, array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('license_number') }} </span>
<div class="form-group">
{{ Form::label('license_file', 'License File:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::file('license_file') }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('license_file') }} </span>
<div class="form-group">
{{ Form::label('street_address', 'Street Address:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::text('street_address', $value = null, array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-symbol">* </span>
</div>
<span class='error-text'> {{ $errors->first('street_address') }} </span>
<div class="form-group">
{{ Form::label('password', 'Password:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::password('password',array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
<span class="required-text">Between 6 and 12 Characters</span>
</div>
<span class='error-text'> {{ $errors->first('password') }} </span>
<div class="form-group">
{{ Form::label('password_confirmation', 'Confirm Password:', array('class' => 'col-sm-3 control-label')) }}
<div class="col-xs-4">
{{ Form::password('password_confirmation', array('rows' => '3', 'required' => 'required', 'autofocus' => 'autofocus', 'class' => 'form-control' )) }}
</div>
</div>
<div class="form-group">
{{ Form::submit('Add Driver', array('class' => 'btn btn-primary center-block sh-request-button sign-up')) }}
</div>
</form>
{{ Form::close() }}
//controller:
public function store()
{
$input = \Input::all();
////echo "</pre>";print_r($input); $file= \Input::file('license_file.name');
$validator = $this->_modelDriver->validator($input);
if ($validator->fails()) {
return \Redirect::route('drivers.create')->withInput($input)->withErrors($validator);
}
else {
echo "test success";exit;
}
}
//validator:
public function validator(array $input, $isUpdate=false)
{
if(!$isUpdate) {
$rules = array(
'first_name'=>'required|alpha|min:2',
'last_name'=>'required|alpha|min:2',
'email'=>'required|email|unique:drivers',
'password'=>'required|between:6,12|confirmed',
'password_confirmation'=>'required|between:6,12'
);
} else {
$rules = array(
'firstname'=>'required|alpha|min:2',
'lastname'=>'required|alpha|min:2',
'email'=>'required|email',
);
}
return Validator::make($input, $rules);
}
I am new to laravel. So if someone can tell what am I doing wrong and how to fix this.
Thanks

This is happening because you are trying to return with the file input.
You should write this
$input = \Input::except('license_file');
return \Redirect::route('drivers.create')->withInput($input)->withErrors($validator);
instead of only
return \Redirect::route('drivers.create')->withInput($input)->withErrors($validator);

Related

How to add grammarly plugin in laravel forms?

I have this file
#section('content')
<form method="post" action="{{ route('member.articles.store') }}" enctype="multipart/form-data"
onSubmit="submit.disabled=true; submit.value='{{ __('Submitting ...') }}'; return true;">
#csrf
<div class="card bg-light">
<div class="card-header">{{ __('Add Article') }}</div>
<div class="card-body">
<div class="form-group">
{{ Form::label('title', __('Title')) }}
{{ Form::text('title', old('title'), ['class' => 'form-control', 'required' => true, 'maxlength' => 190]) }}
</div>
<div class="form-group" style="display: none">
{{ Form::label('slug', __('Slug(URL Key)')) }}
{{ Form::text('slug', old('slug'), ['class' => 'form-control', 'maxlength' => 190]) }}
</div>
<div class="form-group">
{{ Form::label('category', __('Category')) }}
{{ Form::select('category', $categories, old('category'),
['class' => 'form-control select2', 'required' => true]) }}
</div>
<div class="form-group">
{{ Form::label('content', __('Content')) }}
{{ Form::textarea('content', old('content'), ['class' => 'form-control text-editor'])}}
</div>
And i want to add grammarly plugin in content area.
FYI: https://developer.grammarly.com/docs/api/editor-sdk/
I tried this but not working:-
<div class="form-group">
{{ Form::label('content', __('Content')) }}
<grammarly-editor-plugin>
{{ Form::textarea('content', old('content'), ['class' => 'form-control text-editor'])}}
</grammarly-editor-plugin>
</div>

Laravel 5.3 - Sometimes views get broken and show script

I think it's a bit hard to explain with words so I put some screenshots. Sometimes the view get broken after several refresh like 2 out of 5 tries. It always break on content right div until the end of the page.
Not Break: https://i.stack.imgur.com/vpRJU.png
Break After Several Refresh: https://i.stack.imgur.com/swbQ1.png
I think the problem can be at my master blade layout or the page.
This is the Master Blade Layout
<!DOCTYPE html> <html lang="en">
<head>
#include('partial._head')
</head>
<body>
<div class="container main-container">
<div class="row row-bg">
#include('partial._nav')
</div>
<div class="row row-bg">
#include('partial._title')
</div>
<div class="row row-bg">
<div class="col-md-10 col-md-offset-1 content-container">
<div class="text-center text-uppercase content-title">
#yield('content-title')
#yield('session')
</div>
<hr>
<div class="content">
#yield('content')
</div>
</div>
</div>
<div class="row row-bg pb-1">
<div class="col-md-5 col-md-offset-1 content-left">
#yield('content-left')
</div>
<div class="col-md-5 content-right">
#yield('content-right')
</div>
</div>
</div>
#include('partial._footer')
#include('partial._script')
</body>
</html>
This is the Page code
#extends('main')
#section('title', 'Registrasi Akun')
#section('content-title')
Registrasi Akun
#stop
#section('content')
<div class="col-sm-12">
{!! Form::open(['method' => 'POST', 'route' => 'register', 'class' => 'form-horizontal' ]) !!}
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
{!! Form::label('username', 'Username', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::text('username', null, ['class' => 'form-control',
'required' => 'required',
'minlength' => '6',
'maxlength' => '15',
'pattern' => '^[a-zA-Z0-9_-]*$',
'title' => 'only accept alphanum and dashes'
]) !!}
<small class="text-danger">{{ $errors->first('username') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
{!! Form::label('password', 'Password', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::password('password', ['class' => 'form-control',
'required' => 'required',
'minlength' => '8',
'maxlength' => '16'
]) !!}
<small class="text-danger">{{ $errors->first('password') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
{!! Form::label('password_confirmation', 'Password Again', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::password('password_confirmation', ['class' => 'form-control',
'required' => 'required'
]) !!}
<small class="text-danger">{{ $errors->first('password_confirmation') }}</small>
</div>
</div>
<hr>
<div class="form-group{{ $errors->has('fullname') ? ' has-error' : '' }}">
{!! Form::label('fullname', 'Nama Lengkap', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::text('fullname', null, ['class' => 'form-control',
'required' => 'required',
'pattern' => '^[a-zA-Z ]*$',
'title' => 'only accept alphabet and spaces'
]) !!}
<small class="text-danger">{{ $errors->first('fullname') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
{!! Form::label('email', 'Email', ['class' =>'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::email('email', null, ['class' => 'form-control',
'required' => 'required',
'placeholder' => 'eg: foo#bar.com'
]) !!}
<small class="text-danger">{{ $errors->first('email') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('phone_number') ? ' has-error' : '' }}">
{!! Form::label('phone_number', 'No. Telepon', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::text('phone_number', null, ['class' => 'form-control',
'required' => 'required',
'pattern' => '^[0-9]*$',
'title' => 'input number only eg: 081222333444'
]) !!}
<small class="text-danger">{{ $errors->first('phone_number') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('gender') ? ' has-error' : '' }}">
{!! Form::label('gender', 'Input label', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::select('gender', [null => 'Choose...', 'male' => 'Pria', 'female' => 'Wanita'], null, ['id' => 'gender', 'class' => 'form-control',
'required' => 'required'
]) !!}
<small class="text-danger">{{ $errors->first('gender') }}</small>
</div>
</div>
<div class="form-group{{ $errors->has('address') ? ' has-error' : '' }}">
{!! Form::label('address', 'Input', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::textarea('address', null, ['class' => 'form-control',
'required' => 'required',
'minlength' => '50'
]) !!}
<small class="text-danger">{{ $errors->first('address') }}</small>
</div>
</div>
</div>
#stop
#section('content-left')
<div class="form-group">
<div class="checkbox{{ $errors->has('setuju') ? ' has-error' : '' }}">
<label for="setuju" class="text-white">
{!! Form::checkbox('setuju', '1', 0, ['id' => 'setuju', 'required' => 'required']) !!}
Saya telah membaca dan menerima <br> <a class="disini" data-toggle="modal" data-target="#syarat" href="#">Syarat dan Peraturan</a> dari Garena.
</label>
</div>
<small class="text-danger">{{ $errors->first('setuju') }}</small>
</div>
#include('partial._modal')
#stop
#section('content-right')
{!! Form::submit('Register', ['class' => 'btn this-btn btn-garena pull-right']) !!}
{!! Form::close() !!}
#stop
#section('scripts')
<script>
var password = document.getElementById("password"),
confirm_password = document.getElementById("password_confirmation");
function validatePassword(){
if(password.value != confirm_password.value) {
confirm_password.setCustomValidity("Passwords Don't Match");
} else {
confirm_password.setCustomValidity('');
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;
</script>
#stop
where is your 'scripts' yield ?
according to this line #section('scripts') you should have one.

htmlentities() expects parameter 1 to be string, array given when submitting the for

I have this form elements that contains text, select and text which generates array of the received data. for eg: {{ Form::text('email[]', null, ['class' => 'form-control', 'placeholder' => trans('Email')]) }}
If I do not validate the data displays just fine. but when I submit with validation error is displayed.
<div id="home" class="tab-pane fade in active">
<h3>Company Detail
</h3>
<div class="form-group">
{{ Form::label('name', 'Name', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('name', null, ['class' => 'form-control', 'placeholder' => trans('Name')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('country_id', 'Country', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::select('country_id', $country, null, ['class' => 'form-control']) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('city_id', 'City', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::select('city_id', $city, null, ['class' => 'form-control']) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('companyType_id', 'Company Type', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::select('companyType_id', $companyType, null, ['class' => 'form-control']) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('companySubType_id', 'Company Sub Type', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::select('companySubType_id', $companySubType, null, ['class' => 'form-control']) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('description', 'Description', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('description', null, ['class' => 'form-control', 'placeholder' => trans('Discription')]) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('established_year', 'Established Year', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::selectYear('year', 1950, date('Y'), null, ['class' => 'form-control']) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('location', 'Address', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('location', null, ['class' => 'form-control', 'placeholder' => trans('Address')]) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
<div class="form-group">
{{ Form::label('number_of_employees', 'Number Of Employees', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('number_of_employees', null, ['class' => 'form-control', 'placeholder' => trans('Number Of Employees')]) }}
</div>
<!--col-lg-10-->
</div>
<!--form control-->
</div>
<div id="menu1" class="tab-pane fade">
<h3>Other Detail
</h3>
<div class="form-group">
{{ Form::label('email', 'Email', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
<div id="addEmailField">
<p>{{ Form::text('email[]', null, ['class' => 'form-control', 'placeholder' => trans('Email')]) }}
</p>
</div>
<p>
<input type="button" value="Add Email Field" onclick="addEmail();" class="btn btn-success" />
</p>
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('phone_type', 'Phone', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
<div class="form-inline" id="addPhoneField">
<p>
{{ Form::select('phone_type[]', ['home'=>'Home', 'work'=>'Work', 'mobile'=>'Mobile', 'fax'=>'Fax'], null, ['class' => 'form-control']) }}
{{ Form::text('phone_number[]', null, ['class' => 'form-control', 'placeholder' => trans('Phone Number')]) }}
</p>
</div>
<p>
<input type="button" value="Add Phone Field" onclick="addPhone();" class="btn btn-success" />
</p>
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('website_url', 'Website Url', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
<div id="addWebsiteField">
<p>
{{ Form::text('website_url[]', null, ['class' => 'form-control', 'placeholder' => trans('Website Url')]) }}
</p>
</div>
<p>
<input type="button" value="Add Website Field" onclick="addWebsite();" class="btn btn-success" />
</p>
</div>
<!--col-lg-10-->
</div>
</div>
<div id="menu2" class="tab-pane fade">
<h3>Menu 2
</h3>
<div class="form-group">
{{ Form::label('Sunday_open', 'Sunday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Sunday_open', null, ['class' => 'form-control', 'placeholder' => trans('Sunday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Sunday_close', 'Sunday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Sunday_close', null, ['class' => 'form-control', 'placeholder' => trans('Sunday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Monday_open', 'Monday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Monday_open', null, ['class' => 'form-control', 'placeholder' => trans('Monday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Monday_close', 'Monday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Monday_close', null, ['class' => 'form-control', 'placeholder' => trans('Monday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Tuesday_open', 'Tuesday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Tuesday_open', null, ['class' => 'form-control', 'placeholder' => trans('Tuesday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Tuesday_close', 'Tuesday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Tuesday_close', null, ['class' => 'form-control', 'placeholder' => trans('Tuesday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Wednesday_open', 'Wednesday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Wednesday_open', null, ['class' => 'form-control', 'placeholder' => trans('Wednesday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Wednesday_close', 'Wednesday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Wednesday_close', null, ['class' => 'form-control', 'placeholder' => trans('Wednesday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Thursday_open', 'Thursday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Thursday_open', null, ['class' => 'form-control', 'placeholder' => trans('Thursday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Thursday_close', 'Thursday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Thursday_close', null, ['class' => 'form-control', 'placeholder' => trans('Thursday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Friday_open', 'Friday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Friday_open', null, ['class' => 'form-control', 'placeholder' => trans('Friday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Friday_close', 'Friday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Friday_close', null, ['class' => 'form-control', 'placeholder' => trans('Friday Close')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Saturday_open', 'Saturday Open', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Saturday_open', null, ['class' => 'form-control', 'placeholder' => trans('Saturday Open')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('Saturday_close', 'Saturday Close', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('Saturday_close', null, ['class' => 'form-control', 'placeholder' => trans('Saturday Close')]) }}
</div>
<!--col-lg-10-->
</div>
</div>
<div id="menu3" class="tab-pane fade">
<h3>Branch
</h3>
<div id="addBranchField">
<div class="form-group">
{{ Form::label('location', 'Location', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('location[]', null, ['class' => 'form-control', 'placeholder' => trans('Location')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('branch_description', 'Description', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('branch_description[]', null, ['class' => 'form-control', 'placeholder' => trans('Description')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('long', 'Longitude', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('long[]', null, ['class' => 'form-control', 'placeholder' => trans('Longitude')]) }}
</div>
<!--col-lg-10-->
</div>
<div class="form-group">
{{ Form::label('lat', 'Latitude', ['class' => 'col-lg-2 control-label']) }}
<div class="col-lg-10">
{{ Form::text('lat[]', null, ['class' => 'form-control', 'placeholder' => trans('Latitude')]) }}
</div>
<!--col-lg-10-->
</div>
</div>
<!-- addBranchField -->
<p class="col-lg-offset-2">
<input type="button" value="Add Branch Field" onclick="addBranchField();" class="btn btn-success" />
</p>
</div>
as you can see there are input that takes array of values. When I submit the form it displays error.
Also I have the rules for the form
$this->validate($request, [
'companyName' => 'required',
]);
for now I am just printing the submitted value. print_r($request->all());
$this->validate($request, [
'email.*' => 'required',
]);
try to validate array type input data this way

Inserting Data into Database with Laravel 5

I am trying to Update user Profile after they Login, It works well and says PROFILE UPDATED SUCCESSFULLY but nothing inserted on the Database Table, so in essence, the View shows nothing of the Updated form fields. Please anyone with an idea of where i am getting this wrong will be highly appreciated, Thanks.
CONTROLLER Update FUNCTION
public function update(Request $request)
{
$rules = [
'name' => 'required',
'email' => 'required',
'phone' => 'required|numeric',
'country' => 'required',
'gender' => 'required',
'birthday' => 'required',
'fb' => 'url',
'twitter' => 'url',
'gp' => 'url',
'instagram' => 'url',
'personal_site' => 'url',
'aboutme' => 'url',
'linkedin' => 'url',
'pinterest' => 'url'
];
$data= $request->all();
$validator = Validator::make($data, $rules);
if($validator->fails()){
return Redirect::back()->withInput()->withErrors($validator);
}
$user = Auth::user();
$user->name = $data['name'];
$user->email = $data['email'];
$user->phone = $data['phone'];
$user->country = $data['country'];
$user->birthday = $data['birthday'];
$user->address = $data['address'];
if($user->save()) {
$profile_id = $user->id;
$profile = Profile::find($profile_id);
if(count($profile) > 0) {
$profile->gender = $data['gender'];
$profile->city = $data['city'];
$profile->state = $data['state'];
$profile->aboutmyself = $data['aboutmyself'];
$profile->fb = $data['fb'];
$profile->twitter = $data['twitter'];
$profile->gp = $data['gp'];
$profile->instagram = $data['instagram'];
$profile->personal_site = $data['personal_site'];
$profile->aboutme = $data['aboutme'];
$profile->linkedin = $data['linkedin'];
$profile->pinterest = $data['pinterest'];
// $profile = $user->profile()->save($profile);
$profile->save();
}
} else {
return redirect()->back()->withInput()->withInfo("Something went wrong. Please, try again");
}
return redirect()->route('profile')->withSuccess("Your Profile Successfully Updated.");
}
MY VIEW (profile-edit.blade.php)
<div class="form-group row">
{!! Form::model($user, array('route' => 'post.edit.profile', 'method' => 'post', 'class' => 'form-horizontal')) !!}
{!! Form::label('name', "Full Name", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-8">
<div class="row">
<div class="col-md-9">
{!! Form::text('name', null, array('class' => 'form-control', 'placeholder' => 'Your Full Name', 'required' => 'required')) !!}
</div>
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('email', "Email Address", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-6">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">
<i class="material-icons md-18 text-muted">mail</i>
</span>
{!! Form::email('email', null, array('class' => 'form-control', 'placeholder' => '', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('phone', "Phone Number", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-6">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">
<i class="material-icons md-18 text-muted">mail</i>
</span>
{!! Form::text('phone', null, array('class' => 'form-control', 'placeholder' => 'e.g. +8801711223344', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('gender', "Gender", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
{!! Form::select('gender', $gender, array('class' => 'c-select form-control', 'id' => '', 'required' => 'required')) !!}
</div>
</div>
<div class="form-group row">
{!! Form::label('birthday', "Birthday", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('birthday', null, array('class' => 'datepicker form-control', 'placeholder' => '01/28/2016','id' => 'birthday', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('address', "Address", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('address', null, array('class' => 'form-control', 'placeholder' => 'Street No., Area...','id' => 'address', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('city', "City", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('city', $user->profile->city, array('class' => 'form-control', 'placeholder' => 'City', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('state', "State", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('state', $user->profile->state, array('class' => 'form-control', 'placeholder' => 'State', 'required' => 'required')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('country', "Country", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-8">
<div class="row">
<div class="col-md-6">
{!! Form::text('country', null, array('class' => 'form-control', 'placeholder' => 'Country','id' => '')) !!}
</div>
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('aboutmyself', "About Me", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::textarea('aboutmyself', Auth::user()->profile->aboutmyself, array('class' => 'form-control', 'rows' => 4, 'placeholder' => 'About Yourself')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('fb', "Facebook Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('fb', $user->profile->fb, array('class' => 'form-control', 'placeholder' => 'https://facebook.com/username')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('twitter', "Twitter Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('twitter', $user->profile->twitter, array('class' => 'form-control', 'placeholder' => 'https://twitter.com/username')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('gp', "Google+ Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('gp', $user->profile->gp, array('class' => 'form-control', 'placeholder' => 'https://plus.google.com/+username')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('personal_site', "Personal Site", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('personal_site', $user->profile->personal_site, array('class' => 'form-control', 'placeholder' => 'http://www.mywebsite.me')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('instagram', "Instagram Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('instagram', $user->profile->instagram, array('class' => 'form-control', 'placeholder' => 'https://www.instagram.com/username')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('linkedin', "LinkedIn Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('linkedin', $user->profile->linkedin, array('class' => 'form-control', 'placeholder' => 'https://www.linkedin.com/username')) !!}
</div>
</div>
</div>
<div class="form-group row">
{!! Form::label('pinterest', "Pinterest Link", array('class' => 'col-sm-3 control-label')) !!}
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon2">
<i class="material-icons md-18 text-muted">language</i>
</span>
{!! Form::text('pinterest', $user->profile->pinterest, array('class' => 'form-control', 'placeholder' => 'https://www.pinterest.com/username')) !!}
</div>
</div>
</div>
<!-- <div class="form-group row">
<label for="password" class="col-sm-3 form-control-label">Change Password</label>
<div class="col-sm-6 col-md-4">
<div class="input-group">
<span class="input-group-addon" id="basic-addon3">
<i class="material-icons md-18 text-muted">lock</i>
</span>
<input type="text" class="form-control" placeholder="Enter new password">
</div>
</div>
</div> -->
<div class="form-group row">
<div class="col-sm-8 col-sm-offset-3">
<div class="media">
<div class="media-left">
{!! Form::submit('Save Changes', array('class' => 'btn btn-success')) !!}
</div>
<!-- <div class="media-body media-middle p-l-1">
<label class="c-input c-checkbox">
<input type="checkbox" checked>
<span class="c-indicator"></span> Subscribe to Newsletter
</label>
</div> -->
</div>
</div>
</div>
{!! Form::close() !!}
User MODEL (User.php)
<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Zizaco\Entrust\Traits\EntrustUserTrait;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword,EntrustUserTrait {
EntrustUserTrait::can as may;
Authorizable::can insteadof EntrustUserTrait;
}
/**
* The database table used by the model.
*
* #var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = ['name', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* #var array
*/
protected $hidden = ['password', 'remember_token'];
public function profile(){
return $this->hasOne('App\Profile','user_id','id');
}
public function pending(){
return $this->hasMany('App\PendingTransfers', 'user_id', 'id');
}
public function transaction(){
return $this->hasMany('App\Transaction', 'user_id', 'id');
}
}
ROUTE
Route::group(array('middleware' => 'auth'), function()
{
Route::get('logout', ['as' => 'logout', 'uses' => 'Auth\AuthController#logout']);
Route::get('profile', ['as' => 'profile', 'uses' => 'UsersController#profile']);
Route::get('edit-profile', ['as' => 'edit.profile', 'uses' => 'UsersController#edit']);
Route::post('edit-profile', ['as' => 'post.edit.profile', 'uses' => 'UsersController#update']);
Route::post('edit-photo', ['as' => 'post.edit.photo', 'uses' => 'UsersController#photoUpdate']);
Route::get('dashboard', array('as' => 'dashboard', 'uses' => 'Auth\AuthController#dashboard'));
Route::get('change-password', array('as' => 'password.change', 'uses' => 'Auth\AuthController#changePassword'));
Route::post('change-password', array('as' => 'password.doChange', 'uses' => 'Auth\AuthController#doChangePassword'));
UPDATE: Thanks for the Prompt response but that didn't fix it though, Am thinking the Fault might be from the CONTROLLER FUNCTION at this point:
if($user->save()) {
$profile_id = $user->id;
$profile = Profile::find($profile_id);
if(count($profile) > 0) {
$profile->gender = $data['gender'];
$profile->city = $data['city'];
$profile->state = $data['state'];
$profile->aboutmyself = $data['aboutmyself'];
$profile->fb = $data['fb'];
$profile->twitter = $data['twitter'];
$profile->gp = $data['gp'];
$profile->instagram = $data['instagram'];
$profile->personal_site = $data['personal_site'];
$profile->aboutme = $data['aboutme'];
$profile->linkedin = $data['linkedin'];
$profile->pinterest = $data['pinterest'];
// $profile = $user->profile()->save($profile);
$profile->save();
OR Probably from the VIEW Opening Form route/variable $user
{!! Form::model($user, array('route' => 'post.edit.profile', 'method' => 'post', 'class' => 'form-horizontal')) !!}

Call to a member function getClientOriginalName() on a non-object in Laravel 4

I have this problem in my Public function Store of Laravel 4, i can upload an update images, pretty cool, but I cannot create a new record :( appears: Call to a member function getClientOriginalName() on a non-object, in this line:
$filename = $image->getClientOriginalName();This is complete code.
public function store(){
$image = Input::file('image');` <br/>
$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 = $filename;
$titulo->category_id = Input::get('category_id');
$titulo->save();
}
This is my form
{{ Form::open (['route' => 'titulos.store', 'class'=> 'form', 'method' =>'post', '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>
You missed the enctype part. Your open form should be
{{ Form::open (['route' => 'titulos.store', 'enctype' => 'multipart/form-data', 'class'=> 'form', 'method' =>'post', 'files'=> 'true']) }}

Categories