Search data from database in textbox to display - Laravel - php

my problem is i cannot search and cannot disply the values in my texboxes.
what i want is to search the id of each user and display its data to my textbox
How can I do this on this video This Video in Laravel?
as of now I have this
here is my page
View
{!! Form::open(['action' => 'Admin\EmployeeFilemController#search', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<input type="text" name="id" class="form-control" placeholder="Enter ID to Search"><br>
<input type="submit" class="btn btn-primary btn-md" name="search" value="Search Data">
{!! Form::close() !!}
Controller
public function search(Request $request){
$output = "";
$employees = DB::table('employeefms')->where('id')->get();
return redirect('/admin/employeemaintenance');
}
my View Inputs
<div class="form-group col-md-2">
{{Form::label('employee_no', 'Employee No.')}}
{{Form::text('employee_no', '',['class' => 'form-control', 'placeholder' => 'Employee No.'])}}
</div>
<div class="row">
<div class="form-group col-md-4">
{{Form::label('last_name', 'Last Name')}}
{{Form::text('last_name', '',['class' => 'form-control', 'placeholder' => 'Last Name'])}}
</div>
<div class="form-group col-md-4">
{{Form::label('first_name', 'First Name')}}
{{Form::text('first_name', '',['class' => 'form-control', 'placeholder' => 'First Name'])}}
</div>
</div>
<div class="row">
<div class="form-group col-md-4">
{{Form::label('middle_name', 'Middle Name')}}
{{Form::text('middle_name', '',['class' => 'form-control', 'placeholder' => 'Middle Name'])}}
</div>
<div class="form-group col-md-4">
{{Form::label('nick_name', 'Nick Name')}}
{{Form::text('nick_name', '',['class' => 'form-control', 'placeholder' => 'Nick Name'])}}
</div>
</div>

You don't seem to pass the id entered by the user in your controller function.
$employees = DB::table('employeefms')->where('id')->get();
You may have to do the following changes
$input = $request->all();
$id = $input['id']
// $employees = DB::table('employeefms')->where('id', $id)->get();
// actually, if 'id' is the primary key, you should be doing
$employee = DB::table('employeefms')->find($id);
// now pass the data to the view where you want to display the record
// like so
return view('name_of_view', compact('employee'));
Then, use Laravel's Form-Model binding
{!! Form::model($employee,
['action' => ['Admin\EmployeeFilemController#update', $employee->id],
'method' => 'patch' // or whatever method you have defined
]) !!}
// your form fields specified above will go here
{!! Form::close() !!}

Related

Laravel validation with unique fields

I have been trying unique validation in laravel 5.7. Below is my code for validation.
$this->validate($request, [
'name' => 'required|unique:permissions,name',
'slug' => 'required|unique:permissions,slug',
]);
And the html is below:
<div class='container'>
{!! Form::open(array('route' => 'permission.save','method'=>'POST')) !!}
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
{!! Form::text('name', null, array('placeholder' => 'Name','class' => 'form-control')) !!}
</div>
<div class="form-group">
<strong>Slug:</strong>
{!! Form::text('slug', null, array('placeholder' => 'Slug','class' => 'form-control')) !!}
</div>
<div class="form-group">
<strong>Description:</strong>
{!! Form::textarea('description', null, array('placeholder' => 'Description','class' => 'form-control')) !!}
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
{!! Form::close() !!}
</div>
Unique validation for 'name' is working fine but it is not working for 'slug'. It's really weird i can't get it. Please provide suggestions to fix this issue. Any help would be great.
You need to specify column name from database table in unique validation rule
https://laravel.com/docs/5.6/validation#rule-unique
for example your column name for slug is : column_slug
$this->validate($request, [
'name' => 'required|unique:permissions,name',
'slug' => 'required|unique:permissions,column_slug', // column_slug may be different in your case
]);
And ensure that you have set unique key for that column in database table
Hope it helps !

Laravel form with <div> tags in the middle

I am trying to use a form with div tags in the middle. However, it doesnt seem to work, the form works fine when used without them. Is there any way to stylise the form and use it ?
{!! Form::open(['action' => 'ProductController#store', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<div class="centre col-lg-4 col-lg-offset-4 ">
<h2>Product</h2>
{{Form::text('', '', ['class' => 'form-control', 'placeholder' => 'Product'])}}
</div>
<div>
<div class="section3 ">
<div class="container centre">
{{Form::submit('Submit', ['class'=>'btn btn-primary'])}}
</div>
</div>
</div>
{!! Form::close() !!}
You have some unwanted </div> in your code which leads form to close in a wrong place, fix the <div> and it will start working again. Basically, this is an error due to the non-well-formatted code.
<div>
{!! Form::open(['action' => 'ProductController#store', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<div class="centre col-lg-4 col-lg-offset-4 ">
<h2>Product</h2>
{{Form::text('', '', ['class' => 'form-control', 'placeholder' => 'Product'])}}
</div>
<div class="section3 ">
<div class="container centre">
{{Form::submit('Submit', ['class'=>'btn btn-primary'])}}
{!! Form::close() !!}
</div>
</div>
</div>
And don't forget to add name and other parameters in your code to make your form worthy.
{{Form::text('name', null, ['class' => 'form-control', 'placeholder' => 'Product'])}}
first the div tag is not proprly closed ..you have two unwanted tag in first div .
you can style according to your design need .
.
<div class="container">
<div class="well">
{!! Form::open(['action' => 'ProductController#store', 'class' => 'form-inline' , 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<fieldset>
<div class="form-group">
{!! Form::label('product', 'Product:', ['class' => 'col-lg-2 control-
label']) !!}
<div class="col-lg-10">
{!! Form::text('product', $value = null, ['class' => 'form-
control', 'placeholder' => 'product']) !!}
</div>
</div>
<!-- Submit Button -->
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
{!! Form::submit('Submit', ['class' => 'btn btn-info '] ) !!}
</div>
</div>
</fieldset>
{!! Form::close() !!}
</div>
</div>
you can use bootsrap html form for easy and better design since they have different form-class for different design .
https://www.w3schools.com/bootstrap/bootstrap_forms.asp
if u find this helpful
The form close tag should be at the same depth as the form open tag:
without them. Is there any way to stylise the form and use it ?
{!! Form::open(['action' => 'ProductController#store', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<div>
<div>
<div class="centre col-lg-4 col-lg-offset-4 ">
<h2>Product</h2>
{{Form::text('product', $value=null, ['class' => 'form-control', 'placeholder' => 'Product'])}}
</div>
</div>
</div>
<div>
<div class="section3 ">
<div class="container centre">
{{Form::submit('Submit', ['class'=>'btn btn-primary'])}}
</div>
</div>
</div>
{!! Form::close() !!}

Redirect to wrong action when validation fails after form submission in laravel 5.0

I have two form in one view when I leave the text field empty it redirects to wrong action. I am looking forwrad for the solution of this problem. Thanks in hope.
Form one works fine when I enter data in ll the input fields. /inquiry/store also contains http request validation.
View code which contains two forms.
<div class="col-lg-6">
{!! Form::open(['role' => 'form', 'url' => '/inquiry/store', 'class' => 'form-horizontal', 'method'=>'POST']) !!}
<div class='form-group'>
{!! Form::label('name', 'Student Name *', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::text('name', $student->name,['autocomplete'=>'off' , 'placeholder' => 'Student Name', 'class' => 'form-control']) !!}
</div>
</div>
<div class='form-group'>
{!! Form::label('father_name', 'Father Name *', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::text('father_name',$student->father_name, ['autocomplete'=>'off' , 'placeholder' => 'Father Name', 'class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('class', 'Class', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::text('class', $student->admission_class,['autocomplete'=>'off' , 'placeholder' => 'Class', 'class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('roll_no', 'Roll Number', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::text('roll_no', $student->roll_no,['autocomplete'=>'off' , 'placeholder' => 'Roll Number', 'class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('date', 'Date',['class' => 'control-label col-md-4']) !!}
<div class="col-md-8 date">
<div class="input-group input-append date" id="dateRangePicker">
{!! Form::input('date', 'date', null, ['autocomplete'=>'off' , 'placeholder' => 'Date of Birth', 'class'=>'form-control col-height datepicker']) !!}
<span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
</div>
<div class="form-group">
{!! Form::label('teacher_name', 'Teacher Name', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::select('teacher_name', $teacher, ['autocomplete'=>'off' , 'placeholder' => 'Teacher Name', 'class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('remarks', 'Remarks', ['class' => 'control-label col-md-4']) !!}
<div class="col-md-8">
{!! Form::textarea('remarks', null, ['autocomplete'=>'off' ,
'placeholder' => 'Remarks',
'class' => 'form-control']) !!}
</div>
</div>
<div class="form-group">
<div class="col-xs-offset-3 col-md-12">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<input type="reset" class="btn btn-default" value="Reset">
</div>
</div>
{!! Form::close() !!}
second form for searching the student. When I submit the first form with out some empty field it redirect to /inquiry/search_stu. and displays MethodNotAllowedHttpException .
<form role="form" id="search_form" action="/inquiry/search_stu" method="post" class="form-inline">
<div class='form-group'>
<label class="control-label col-md-4">Search Student *</label>
<input class="form-control" type="text" name="search" placeholder="Admission No" required>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class='form-group'>
<input type="submit" form="search_form" class="btn btn-primary" name="submit">
<input type="reset" class="btn btn-default">
</div>
</form>
Controller function for search student.
public function search_student(Request $request)
{
$teacher = \App\Teacher::lists('name', 'name');
$adminid = $request['search'];
$student = Admission::where('admission_no',$adminid)->first();
return View::make('/inquiry/create', ['student'=> $student,'teacher' => $teacher]);
}
When I submit the store form it redirects to search student.
store function .
public function store(Requests\StoreInquiryRequest $request) {
$input = Input::all();
$inquiry = new Inquiry();
$inquiry->name = $input['name'];
$inquiry->father_name = $input['father_name'];
$inquiry->date = $input['date'];
$inquiry->class = $input['class'];
$inquiry->teacher_name = $input['teacher_name'];
$inquiry->roll_no = $input['roll_no'];
$inquiry->remarks = $input['remarks'];
try {
$inquiry->save();
return redirect()->to('inquiry')->with('message', 'success| Student details have been saved.');
} catch (Exception $ex) {
\Log::error($ex);
return redirect()->to('inquiry')->with('message', 'error| There was an error adding new student, please try again later.');
}
}
Http request for validation when wants to store data
public function rules()
{
$cid = \Route::input('id');
$isEdit = isset($cid) ? true : false;
$rules = array(
'name' => 'required|string|Max:50',
'father_name' => 'required|string|Max:50',
'class' => 'required|string|Max:50',
'date' => 'required|date|Max:50',
'teacher_name' => 'required|string|Max:50',
'remarks' => 'required',
'roll_no' => 'required',
);
return $rules;
}
You can performe as many forms on one page as you wish. As far as I see you should have proper validtion in your controller - different validation for each form.
You need to use proper Laravel Validation. Reading this will make your coding process easier and faster: https://laravel.com/docs/5.0/validation
Example of validation in controller in Laravel 5.0:
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required|unique|max:255',
'body' => 'required',
]);
}
Laravel Valiation also let you perform validations with query to database qithout writing whole SQL query: https://laravel.com/docs/5.0/validation#available-validation-rules
To display errors in view use:
#if($errors->has())
#foreach ($errors->all() as $error)
<div>{{ $error }}</div>
#endforeach
#endif
Good luck!

Couldn't add required input in the form [duplicate]

This is my code :
<div class="form-group">
<div class="col-md-4">
<label class="control-label">Mobile Number:</label>
</div>
<div class="col-md-8">
{!! Form::input('number', 'mobile', null, ['type' => 'number', 'min' => 0, 'id' => 'mobile', 'class' => 'input-lg form-control TabOnEnter', 'placeholder' => 'Eg: 9876543210', 'tabindex' => 15]) !!}
</div>
</div>
Here i want to give this mobile number field as required, how can i add it in my code?
And i am having 3 steps in the creation of form and i am having mobile number in step1, when i am clicking the next button without adding mobile number, it should display an alert message..Now it is displaying alert message of mobile field required, only after clicking submit button in last step (i.e) in step 3..
Add 'required' => true to the array:
{!! Form::input('number', 'mobile', null, ['required' => true, 'type' => 'number'....
You need to check it with your next_button using jquery
<div class="form-group">
<div class="col-md-4">
<label class="control-label">Mobile Number:</label>
</div>
<div class="col-md-8">
{!! Form::input('number', 'mobile', null, ['type' => 'number', 'min' => 0, 'id' => 'mobile', 'class' => 'input-lg form-control TabOnEnter', 'placeholder' => 'Eg: 9876543210', 'tabindex' => 15]) !!}
<button style="margin-right:20px;" class="next_button btn btn-info active nextBtn btn-md pull-right" type="next" >Next</button>
</div>
</div>
$(document).ready(function(){
$('.next_button').click(function(event){
if ($('#mobile').val() == ""){
event.preventDefault();
alert('Enter the number');
}
});
});
Added next_button class in your existing code

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')) !!}

Categories