Laravel : Form not submitting but everything looks right? - mysql

I have a very strange problem with Laravel . I'm sure I miss something but not sure what.
When submit there's no record in DB. But it's very strange that not submit even without validator. Here is the code.
The model:
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class Registration extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* #var string
*/
protected $table = 'register';
protected $fillable = array('first_name','middle_name','last_name','address','phone','email','age','growth','weight','shoe_size','cloth_size','languages','eye_color');
}
The Controller :
<?php
class RegistrationController extends BaseController {
public function getAgency() {
return View::make('agency');
}
public function postAgency(){
$rules = array(
'first_name' => 'required',
'middle_name' => 'required',
'last_name' =>'required',
'address' => 'required',
'phone' => 'required',
'email' => 'required|email',
'age' => 'required',
'growth' =>'required',
'weight' => 'required',
'shoe_size' => 'required',
'cloth_size' => 'required',
'languages' => 'required',
'eye_color' => 'required'
);
$validator = Validator::make(Input::all(),$rules);
if ($validator->fails()) {
return Redirect::to('/agency')->withErrors($validator)->withInput();
}
else {
$registration = new Registration;
$registration->first_name = Input::get('first_name');
$registration->middle_name = Input::get('middle_name');
$registration->last_name = Input::get('last_name');
$registration->address = Input::get('address');
$registration->phone = Input::get('phone');
$registration->email = Input::get('email');
$registration->age = Input::get('age');
$registration->growth = Input::get('growth');
$registration->weight = Input::get('weight');
$registration->shoe_size = Input::get('shoe_size');
$registration->cloth_size = Input::get('cloth_size');
$registration->languages = Input::get('languages');
$registration->eye_color = Input::get('eye_color');
$registration->save();
return Redirect::to('/agency')->with('global',"Thank You!");
}
}
}
The View (agency.blade.php):
#extends('layouts.main')
#section('content')
<div class="container">
<div class="stepwizard">
<div class="stepwizard-row setup-panel">
<div class="stepwizard-step">
1
<p><img src="images/leftShoe.png" alt="" class="shoes"></p>
</div>
<div class="stepwizard-step">
2
<p><img src="images/rightShoe.png" alt="" class="shoes"></p>
</div>
<div class="stepwizard-step">
3
<p><img src="images/duoShoes.png" alt="" class="shoes"></p>
</div>
</div>
</div>
<form method="POST" action="{{URL::action('agency-post')}}">
<div class="row setup-content" id="step-1">
<div class="col-md-12">
<button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button>
</div>
</div>
<div class="row setup-content" id="step-2">
<div class="col-xs-12">
<div class="col-md-12">
<div class="form-group">
<label>First Name</label>
<input type="text" id="name" class="form-control" name="first_name" placeholder="First Name">
#if ($errors->has('first_name')) <p class="help-block">{{ $errors->first('first_name') }}</p> #endif
</div>
<div class="form-group">
<label >Middle Name</label>
<input type="text" id="name" class="form-control" name="middle_name" placeholder="Middle Name">
#if ($errors->has('middle_name')) <p class="help-block">{{ $errors->first('middle_name') }}</p> #endif
</div>
<div class="form-group">
<label >Last Name</label>
<input type="text" id="name" class="form-control" name="last_name" placeholder="Last Name">
#if ($errors->has('last_name')) <p class="help-block">{{ $errors->first('last_name') }}</p> #endif
</div>
<div class="form-group">
<label >Address</label>
<input type="text" id="name" class="form-control" name="address" placeholder="Address">
#if ($errors->has('address')) <p class="help-block">{{ $errors->first('address') }}</p> #endif
</div>
<div class="form-group">
<label >Phone</label>
<input type="text" id="name" class="form-control" name="phone" placeholder="Phone">
#if ($errors->has('phone')) <p class="help-block">{{ $errors->first('phone') }}</p> #endif
</div>
<div class="form-group">
<label >Email</label>
<input type="email" id="email" class="form-control" name="email" placeholder="super#cool.com">
#if ($errors->has('email')) <p class="help-block">{{ $errors->first('email') }}</p> #endif
</div>
<div class="form-group">
<label >Age</label>
<input type="text" id="email" class="form-control" name="age" placeholder="Age">
#if ($errors->has('age')) <p class="help-block">{{ $errors->first('age') }}</p> #endif
</div>
<div class="form-group">
<label >Growth</label>
<input type="text" id="email" class="form-control" name="growth" placeholder="Growth">
#if ($errors->has('growth')) <p class="help-block">{{ $errors->first('growth') }}</p> #endif
</div>
<div class="form-group">
<label >Weight</label>
<input type="text" id="email" class="form-control" name="weight" placeholder="Weight">
#if ($errors->has('weight')) <p class="help-block">{{ $errors->first('weight') }}</p> #endif
</div>
<div class="form-group">
<label >Shoe size</label>
<input type="text" id="email" class="form-control" name="shoe_size" placeholder="Shoe size">
#if ($errors->has('shoe_size')) <p class="help-block">{{ $errors->first('shoe_size') }}</p> #endif
</div>
<div class="form-group">
<label >Size Clothing</label>
<input type="text" id="email" class="form-control" name="cloth_size" placeholder="Cloth Size">
#if ($errors->has('cloth_size')) <p class="help-block">{{ $errors->first('cloth_size') }}</p> #endif
</div>
<div class="form-group">
<label >Spoken Languages</label>
<input type="text" id="email" class="form-control" name="languages" placeholder="Spoken Languages">
#if ($errors->has('languages')) <p class="help-block">{{ $errors->first('languages') }}</p> #endif
</div>
<div class="form-group">
<label >Eye Color</label>
<input type="text" id="email" class="form-control" name="eye_color" placeholder="Eye Color">
#if ($errors->has('eye_color')) <p class="help-block">{{ $errors->first('eye_color') }}</p> #endif
</div>
<div class="form-group">
<button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button>
</div>
</div>
</div>
<div class="row setup-content" id="step-3">
<div class="col-xs-12">
<div class="col-md-12">
<h3> Additional Information</h3>
<div class="form-group">
<label class="control-label">Skills</label>
<textarea maxlength="500" class="form-control" rows="5" placeholder="Enter your skills"></textarea>
</div>
<div class="form-group">
<label class="control-label">Additional Information</label>
<textarea maxlength="500" type="text" class="form-control" rows="5" placeholder="Enter additional information for you"></textarea>
</div>
{{Form::token()}}
{{Form::submit('Finish!')}}
</div>
</div>
</div>
Route.php
Route::get('/agency',array(
'as' => 'agency',
'uses' => 'RegistrationController#getAgency'
));
Route::post('/agency',array(
'as' => 'agency-post',
'uses' => 'RegistrationController#postAgency'
));
It's more strange that when write in loop $validator->fails() { return 'fails';}
page only reload nothing happens.

Related

Button type submit Vs Input type submit | laravel 8

I have a form to register a student.
The form submits when i use the following code
<div class="text-xs-right">
<i class="ti-save-alt"></i> <input type="submit" class="btn btn-info btn-rounded mb-5" value="Register">
</div>
But it just refreshes if i use the Button type Submit (below code)
<button type="submit" value="Submit" class="btn btn-rounded btn-primary btn-outline">
<i class="ti-save-alt"></i> Register
</button>
Can someone please help me understand what am i doing wrong here?
I tried to check if there is any jquery/Js Conflicts by commenting out the scripts. Nothing works.
I need to have the button working, as i am using fa icons to style them.
Thank in advance.
My full form code
<form class="form" method="post" action="{{ route('learner.store') }}">
#csrf
<div class="box-body">
<h4 class="box-title text-info"><i class="ti-user mr-15"></i> Personal Info</h4>
<hr class="my-15">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>CPR Number</label>
<input type="text" name="cprnumber" class="form-control" placeholder="CPR Number" required data-validation-required-message="This field is required">
</div>
#error('cprnumber')
<span class="text-info">{{ $message }}</span>
#enderror
</div>
<div class="col-md-4">
<div class="form-group">
<label>First Name</label>
<input type="text" name="firstname" class="form-control" placeholder="First Name">
</div>
#error('firstname')
<span class="text-info">{{ $message }}</span>
#enderror
</div>
<div class="col-md-4">
<div class="form-group">
<label>Middle Name</label>
<input type="text" name="middlename" class="form-control" placeholder="Middle Name">
</div>
#error('middlename')
<span class="text-info">{{ $message }}</span>
#enderror
</div>
<div class="col-md-4">
<div class="form-group">
<label>Last Name</label>
<input type="text" name="lastname" class="form-control" placeholder="Last Name">
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>Gender</label>
<select name="learnergender" id="select" required class="form-control">
<option value="">Select</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Date of Birth</label>
<input type="date" name="learnerdob" class="form-control" required data-validation-required-message="This field is required">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Nationality</label>
<select name="learnernationality" id="select" required class="form-control">
<option value="">Select</option>
<option value="Bahraini">Bahraini</option>
<option value="Non-Bahraini">Non Bahraini</option>
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Marital Status</label>
<select name="learnermaritalstatus" id="select" required class="form-control">
<option value="">Select</option>
<option value="Single">Single</option>
<option value="Married">Married</option>
<option value="Divorced">Divorced</option>
<option value="Widowed">Widowed</option>
</select>
</div>
</div>
</div>
<h4 class="box-title text-info"><i class="ti-save mr-15"></i> Contact Details</h4>
<hr class="my-15">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>E-mail</label>
<input type="email" name="learneremail" class="form-control" placeholder="E-mail">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Mobile Number</label>
<input type="text" name="learnermobile" class="form-control" placeholder="Phone">
</div>
</div>
</div>
<div class="row">
<div class="col-md-3">
<div class="form-group">
<label>Building Number</label>
<input type="text" name="buildingnumber" class="form-control" placeholder="Building Number">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Road Number</label>
<input type="text" name="roadnumber" class="form-control" placeholder="Road Number">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Block Number</label>
<input type="text" name="blocknumber" class="form-control" placeholder="Block Number">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Area</label>
<input type="text" name="area" class="form-control" placeholder="Area">
</div>
</div>
</div>
<h4 class="box-title text-info"><i class="ti-save mr-15"></i> Education Details</h4>
<hr class="my-15">
<div class="row">
<div class="col-md-2">
<div class="form-group">
<label>Education Level</label>
<select name="educationlevel" id="select" required class="form-control">
<option value="">Select</option>
<option value="Primary">Primary</option>
<option value="Preparatory">Preparatory</option>
<option value="Secondary">Secondary</option>
<option value="Diploma">Diploma</option>
<option value="Bachelor">Bachelor</option>
<option value="Masters/PHD">Masters/PHD</option>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label>Grade</label>
<input type="text" name="learnergrade" class="form-control" placeholder="Grade">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Graduation Date</label>
<input type="date" name="graduationdate" class="form-control" required data-validation-required-message="This field is required">
</div>
</div>
</div>
<h4 class="box-title text-info"><i class="ti-save mr-15"></i> Organisation Details</h4>
<hr class="my-15">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Organisation</label>
<input type="text" name="organisation" class="form-control" placeholder="Organisation">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Office E-mail</label>
<input type="email" name="officeemail" class="form-control" placeholder="Office E-mail">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>Office Number</label>
<input type="text" name="officenumber" class="form-control" placeholder="Office Phone">
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<label>Position</label>
<input type="text" name="position" class="form-control" placeholder="Position">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label>Department</label>
<input type="text" name="department" class="form-control" placeholder="Department">
</div>
</div>
</div>
<div class="form-group">
<label>Description</label>
<textarea rows="5" name="description" class="form-control" placeholder="Description/Remarks/Notes"></textarea>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<!-- <button type="button" class="btn btn-rounded btn-warning btn-outline mr-1">
<i class="ti-trash"></i> Cancel
</button>
<button type="submit" value="Submit" class="btn btn-rounded btn-primary btn-outline">
<i class="ti-save-alt"></i> Register
</button> -->
<div class="text-xs-right">
<input type="submit" class="btn btn-info btn-rounded mb-5" value="Register">
</div>
</div>
</form>
Store method
public function LearnerManagementStore(Request $request){
$validatedData =$request->validate([
'cprnumber' => 'required|unique:learner_management',
'firstname' => 'required',
'lastname' => 'required',
'learnerdob' => 'required',
'learneremail' => 'required',
'learnermobile' => 'required',
]);
$data = new LearnerManagement();
$data->cprnumber = $request->cprnumber;
$data->firstname = $request->firstname;
$data->middlename = $request->middlename;
$data->lastname = $request->lastname;
$data->learnergender = $request->learnergender;
$data->learnerdob = $request->learnerdob;
$data->learnernationality = $request->learnernationality;
$data->learnermaritalstatus = $request->learnermaritalstatus;
$data->learneremail = $request->learneremail;
$data->learnermobile = $request->learnermobile;
$data->buildingnumber = $request->buildingnumber;
$data->roadnumber = $request->roadnumber;
$data->blocknumber = $request->blocknumber;
$data->area = $request->area;
$data->educationlevel = $request->educationlevel;
$data->learnergrade = $request->learnergrade;
$data->graduationdate = $request->graduationdate;
$data->organisation = $request->organisation;
$data->officeemail = $request->officeemail;
$data->officenumber = $request->officenumber;
$data->position = $request->position;
$data->department = $request->department;
$data->description = $request->description;
$data->save();
$notification = array (
'message' => 'Learner Added successfully',
'alert-type' => 'success'
);
return redirect()->route('learners.viewall')->with($notification);
}
Route
// Learner Management
Route::prefix('learner')->group(function(){
Route::get('/viewall', [LearnerController::class, 'LearnerManagementViewall'])-> name('learners.viewall');
Route::get('/view/{id}', [LearnerController::class, 'LearnerManagementView'])-> name('learner.view');
Route::get('/add', [LearnerController::class, 'LearnerManagementAdd'])-> name('learner.add');
Route::post('/store', [LearnerController::class, 'LearnerManagementStore'])-> name('learner.store');
Route::get('/edit/{id}', [LearnerController::class, 'LearnerManagementEdit'])-> name('learner.edit');
Route::post('/update/{id}', [LearnerController::class, 'LearnerManagementUpdate'])-> name('learner.update');
Route::get('/delete/{id}', [LearnerController::class, 'LearnerManagementDelete'])-> name('learner.delete');
});

SQLSTATE[42S22]: Column not found: 1054 Unknown column '_method'

I don't really understand why this #method('PUT') is doing Unknown column '_method'in my SQL. I will show you all the code that's possibly the reason of this error below. Laravel version 6.2.
SQLSTATE[42S22]: Column not found: 1054 Unknown column '_method' in
'where clause' (SQL: update setups set _method = PUT, id = 1,
image = admitad-e1504616712278.png, meta_title = testing,
address = testing, contact = testing#testing, email = testing,
social = ["testing","testing"], updated_at = 2019-12-29 15:40:21
where _method = PUT)
2019_12_23_171326_create_setups_table.php
public function up()
{
Schema::create('setups', function (Blueprint $table) {
$table->increments('id');
$table->string('image')->nullable();
$table->string('meta_title');
$table->string('address');
$table->string('contact');
$table->string('email');
$table->string('social');
$table->timestamps();
});
}
edit.blade.php
<form class="card-body" method="POST" action="{{ route('setups.update', $data->id) }}">
#csrf
#method('PUT')
<input type="hidden" name="tbl" value="{{encrypt('setups')}}">
<input type="hidden" name="id" value="{{ $data->id }}">
<div class="col-sm-3">
<div class="form-group" style="left: 5px; padding: 30px 0 30px">
<input type="file" accept="image/*" name="image" id="file" onchange="loadFile(event)" style="display: none">
<img id="output" width="150" style="box-shadow: 0px 16px 18px -4px rgba(0,0,0,0.17);"/>
<label class="card-title" for="file" style="cursor: pointer; padding: 10px 0 0px">Upload Logo</label>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="bmd-label-floating">Site title</label>
<input type="text" name="meta_title" value="{{ $data -> meta_title }}" class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="bmd-label-floating">Address</label>
<input type="text" name="address" value="{{ $data -> address }}" class="form-control">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="bmd-label-floating">Contant number</label>
<input type="email" name="contact" value="{{ $data -> contact }}" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="bmd-label-floating">Email</label>
<input type="text" name="email" value="{{ $data -> email }}" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12" id="socialGroup">
#foreach($socials as $social)
<div class="form-group socialField">
<label class="bmd-label-floating">Social Links</label>
<input type="text" name="social[]" value="{{ $social }}" class="form-control">
<i class="fa fa-plus"></i>
</div>
#endforeach
<div class="alert alert-danger" id="socialError">
<p><strong>Sorry! </strong>You've reached the max number for social links form.</p>
</div>
</div>
</div>
<button type="submit" class="btn btn-primary pull-right">Update Profile</button>
<div class="clearfix"></div>
</form>
SetupController.php
public function update(Request $request, Setup $setup)
{
$data = Input::except('_token', 'submit');
$tbl = decrypt($data['tbl']);
unset ($data['tbl']);
if(!empty($data['image'])){
if(Input::hasFile('image')){
$data['image'] = $this->upload($data['image'], $tbl);
}
}
$data['updated_at'] = date('Y-m-d H:i:s');
DB::table($tbl)->where(key($data), reset($data))->update($data);
session::flash('message','SetupController updated successfully!!!');
return redirect()->route('setups.index');
}
web.php
Route::resource('setups','SetupController');
#method('PUT')
always print
<input name="_method" type="hidden" value="PUT">
into source html, if you don't want to use this you can remove or you want eliminate them add one more value in your code :
$data = Input::except('_token', 'submit','_method');

what is wrong in this it is not inserting [duplicate]

i have a small problem here and it is that the image field doesn't have a default value as the complier said but actually i assigned a value for it i know that this error pops up when the field should have a value but the programmer didn't assign a value to it i know all of this but i already assigned a value to my field so what i am missing here
controller
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'image' => ['required' , 'image' , 'mimes:jpeg,png,jpg', 'max:2048'],
]);
}
protected function create(array $data)
{
$imageName = time().'.'.request()->image->getClientOriginalExtension();
request()->image->move(public_path('images'), $imageName);
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'image' => $imageName,
'password' => Hash::make($data['password']),
]);
}
view
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}" enctype="multipart/form-data">
#csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="new-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
</div>
</div>
<label class="col-md-4 col-form-label text-md-right" >Upload a picture</label>
<div class="custom-file mb-3 col-sm-6">
<input type="file" class="custom-file-input center" id="image" name="image">
<label class="custom-file-label" for="customFile"></label>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
the problem is mainly from the controller but i said that i put the view just in case you want to see it
small note : the image is uploading and it is stored at public folder just like the code said but its name doesn't save at the database also the field image is string at my database because i just want its name so i could view it
snap shot
Set a default image for your image field. Also make sure you have made it fillable, if not set it in protected $fillable in your model User.php
You will get this error when a user doesn't upload an image.
$table->string('image')->default('default.jpg');//You can also add .png
Now have a default image in your storage with name default.jpg
This way the image will have a default value if user doesn't' upload it.
You need to add the default value or make that field null in the migration file, not the controller or view.
$table->string('image')->nullable();
or...
$table->string('image')->default('value');

error when updating table (crud) in laravel

When I get ready to edit the table I get the following error:
"The POST method is not supported for this route. Supported methods:
GET, HEAD."
<?php
Route::get('/crear',[
'uses'=>'CarController#mostrar',
'as'=>'cars.create'
]
);
Route::post('/crear',[
'uses'=>'CarController#crear',
'as'=>'cars.crear'
]);
Route::get('/', 'CarController#casa' );
Route::post('cars/{id?}/editar', 'CarController#edit')->name('editarcar');
Route::post('cars/{id?}/editar', 'CarController#update');
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::resource('cars', 'CarController');
In View
#extends('layouts.app')
#section('title', 'Contact')
#section('content')
<div class="container col-md-8 col-md-offset-2">
<div class="well well bs-component">
<form class="form-horizontal" method="post">
#foreach ($errors->all() as $error)
<div class="alert alert-danger">{{ $error }}</div>
#endforeach
#if(session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
#endif
{!! csrf_field() !!}
<fieldset>
<legend>Editar </legend>
<div class="form-group">
<label for="patente" class="col-lg-label">patente</label>
<div class="col-lg-10">
<input type="text" name="patente"size="6" maxlength="6" class="form-control"required>
</div>
</div>
<div class="form-group">
<label for="marca" class="col-lg-label">marca</label>
<div class="col-lg-10">
<input type="text" name="marca" class="form-control" required>
</div>
</div>
<div class="form-group">
<label for="modelo" class="col-lg-label">modelo</label>
<div class="col-lg-10">
<input type="text" name="modelo" class="form-control" required>
</div>
</div>
<div class="form-group">
<label for="color" class="col-lg-label">color</label>
<div class="col-lg-10">
<input type="text" name="color" class="form-control" required>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button class="btn btn-default">Cancelar</button>
<button type="submit" class="ntm btn-primary">Actualizar</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
#endsection
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
namespace App\Http\Controllers;
use App\Car;
use Illuminate\Http\Request;
public function edit($id)
{
$car = car::whereid($id)->firstOrFail();
return view('edit', compact('cars'));
}
public function update(Request $request, $id)
{
$car = car::whereid($id)->firstOrFail();
$car->patente = $request->post('patente');
$car->marca = $request->post('marca');
$car->modelo = $request->post('modelo');
$car->color = $request->post('color');
$car->save();
return redirect(action('CarsController#edit', $car->id))->with('status', 'El car ' . $id . ' ha sido actualizado');
}
Update your controller > edit action with correct variable compact.
public function edit($id)
{
$car = car::whereid($id)->firstOrFail();
return view('edit', compact('car'));
}
Add a form action like {{ route("cars.update", ['car' => $car->id]) }} so your view looks like:
#extends('layouts.app')
#section('title', 'Contact')
#section('content')
<div class="container col-md-8 col-md-offset-2">
<div class="well well bs-component">
<form class="form-horizontal" action="{{ route("cars.update") }}" method="post">
#foreach ($errors->all() as $error)
<div class="alert alert-danger">{{ $error }}</div>
#endforeach
#if(session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
#endif
{!! csrf_field() !!}
<fieldset>
<legend>Editar </legend>
<div class="form-group">
<label for="patente" class="col-lg-label">patente</label>
<div class="col-lg-10">
<input type="text" name="patente"size="6" maxlength="6" class="form-control"required>
</div>
</div>
<div class="form-group">
<label for="marca" class="col-lg-label">marca</label>
<div class="col-lg-10">
<input type="text" name="marca" class="form-control" required>
</div>
</div>
<div class="form-group">
<label for="modelo" class="col-lg-label">modelo</label>
<div class="col-lg-10">
<input type="text" name="modelo" class="form-control" required>
</div>
</div>
<div class="form-group">
<label for="color" class="col-lg-label">color</label>
<div class="col-lg-10">
<input type="text" name="color" class="form-control" required>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button class="btn btn-default">Cancelar</button>
<button type="submit" class="ntm btn-primary">Actualizar</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
#endsection

Registering form is not storing data in database

Well I am using this form to register a user in database but It is not successfully being storing data. While RegisterContoller.php is in Auth section. And I have given route: Auth::routes();. But still I why it is not storing data.
Register.blade.php
<form style="margin-left: 30%; margin-right: 30%; margin-top: 5%;" class="form-horizontal" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<div class="form-group organic-form-2 {{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name">Your Name *</label>
<input id="name" class="form-control" type="text" name="name" value="{{ old('name') }}" required autofocus>
#if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
<div class="form-group organic-form-2 {{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email">Your Email *</label>
<input id="email" class="form-control" type="email" name="email" value="{{ old('email') }}" required>
</div>
<div class="form-group organic-form-2">
<label>Password *</label>
<input class="form-control" type="Password">
</div>
<div class="form-group organic-form-2">
<label>Repeat Password *</label>
<input class="form-control" type="Password">
</div>
<div class="form-group remember-me">
<div class="checkbox pull-left">
<label>
<input type="checkbox" name="value1"> Privacy Policy Agreement?
</label>
</div>
</div>
<div class="form-group footer-form">
<button class="btn btn-brand pill" type="submit">SUBMIT</button>
</div>
</form>
</div>
</div>
</div>
</section>
</div>
RegisterController.php
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
It seems you miss input names in your form.
Instead of:
<div class="form-group organic-form-2">
<label>Password *</label>
<input class="form-control" type="Password">
</div>
<div class="form-group organic-form-2">
<label>Repeat Password *</label>
<input class="form-control" type="Password">
</div>
use:
<div class="form-group organic-form-2">
<label>Password *</label>
<input class="form-control" type="Password" name="password">
</div>
<div class="form-group organic-form-2">
<label>Repeat Password *</label>
<input class="form-control" type="Password" name="password_confirmation">
</div>