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

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');

Related

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

data not updating on laravel 5.4?

Here is my edit.blade file.Please notice on From tag action attribute.Is this Ok?
#extends('admin_theme.master')
#section('title','Add Category')
#section('content')
#if(Auth::check())
<script>
function validselect(){
var ind=document.getElementById('my_select').selectedIndex;
if(ind==0){
alert("please select an Valid Option");
}
}
</script>
<div class="forms">
<div class=" form-grids form-grids-right">
<div class="widget-shadow " data-example-id="basic-forms">
<div class="form-title">
<h4>Ready To ADD:</h4>
</div>
<div class="form-body">
<form class="form-horizontal" action={{route('category.update',$singledata->id)}} method="put">
{{ csrf_field() }}
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Category Name</label>
<div class="col-sm-9">
<input class="form-control" id="inputEmail3" placeholder="Name" type="text" value="{{$singledata->name}}" name="name">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Status</label>
<div class="col-sm-9">
<Select class="form-control" id="my_select"onchange="validselect()" name="status">
<option>Select availability</option>
<option value="1" #if($singledata->status==1){{"selected"}} #endif >Active</option>
<option value="0" #if($singledata->status==0){{"selected"}} #endif>DeActive</option>
</Select>
</div>
</div>
<div class="form-group">
</div>
<div class="col-sm-offset-2"> <button type="submit" class="btn btn-default" >Update</button>
</div>
</form>
</div>
</div>
</div>
</div>
#endif
#endsection
Here is my update method in controller and here the inputted data from edit page not found in $request object.I changed the html method like as PUT or PATCH but no luck :)
public function update(Request $request, $id)
{
$allinput=$request->all();
// dd($allinput);
// dd($allinput);
$data=Category::findorfail($id);
$data->update($allinput);
return view('admin_theme.dynamic_files.category.allCategory');
}
here is my route
<?php
Route::get('/', function () {
return view('my_theme.index');
});
Auth::routes();
Route::get('/admin', 'HomeController#index');
Route::resource('category','CategoryController');
In before (doing CRUD) the store() method works fine the problem is when i update data...i am stuck on this,please help me on this.Thanks in advance
Atlast solved
adding method="POST" in form tag and also add below line after {{csrf_field()}}
<input name="_method" type="hidden" value="PATCH">
but why this line need ?dont know.If anyone make me understand i will be thankfull :)

Can't submit form with "attributes" input field

I have a form with the following setup:
<div class="row">
<div class="col-3">
#include('acp.sidebar')
</div>
<div class="col-9">
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form-horizontal" role="form" method="POST" action="{{ url('acp/provider/add') }}" enctype="multipart/form-data">
{{ csrf_field() }}
<input type="hidden" name="id">
<fieldset>
<legend>Grunddaten</legend>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="form-group">
<label for="description">Beschreibung</label>
<textarea class="form-control" id="description" name="description" required></textarea>
</div>
<div class="form-group">
<label for="url">Domain</label>
<input type="text" class="form-control" id="url" name="url" required>
</div>
<div class="form-group">
<label for="ref">Ref-Code</label>
<input type="text" class="form-control" id="ref" name="ref" required>
</div>
<div class="form-group">
<label for="image">Logo</label>
<input type="file" name="image" id="image" class="form-control" accept="image/*">
</div>
<div class="form-group">
<label for="checkboxes">Payment-Anbieter</label>
<div>
#foreach($paymentProviders as $key => $provider)
<label class="checkbox-inline" for="checkboxes-{{$key}}">
<input name="paymentProviders[]" id="checkboxes-{{$key}}" value="{{$provider->id}}" type="checkbox">
<img src="{{url('/images/paymentProvider/small/'.$provider->image)}}">
{{$provider->name}}
</label>
#endforeach
</div>
</div>
</fieldset>
<fieldset>
<legend>Crawler</legend>
<div class="form-group">
<label for="attributes">Suchattribute</label>
<input type="text" class="form-control" id="attributes" name="attributes" required>
</div>
<div class="form-group">
<label for="crawlerType">Typ</label>
<select id="crawlerType" name="crawlerType" class="form-control">
#foreach($crawlerTypes as $crawlerType)
<option value="{{$crawlerType}}">{{$crawlerType}}</option>
#endforeach
</select>
</div>
</fieldset>
<div class="form-group">
<div class="pull-right">
<button type="submit" class="btn btn-primary">
Absenden
</button>
</div>
</div>
</form>
</div>
</div>
As you can see there is a input named "attributes" down below. When I add this, I can't submit my form. It's like clicking on a button with no "submit" attribute.
After removing or renaming this input, it works. It's not a big thing to rename my input - I'm just interested if this is a bug, or a for me unkown feature.
I'm using Bootstrap v4.0.0-alpha.6 and Laravel 5.4.22.

Laravel 5.4 UnexpectedValueException in Response.php line 444 in form submition

I am making multiauth. When I submit admin email and password from admin login view I got bellow error
"UnexpectedValueException in Response.php line 444:
The Response content must be a string or object implementing __toString(), "boolean" given."
here is my form
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Admin Login</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ route('admin.login.submit') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
And here is route
Route::prefix('admin')->group(function (){
Route::post('/login', 'Auth\AdminLoginController#login')->name('admin.login.submit');
});
And the controller is here
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class AdminLoginController extends Controller
{
public function __construct()
{
$this->middleware('guest');
}
public function showLoginForm()
{
return view('admin.auth.login');
}
public function login(Request $request)
{
return true;
}
}
What wrong here?
And How can I solve it?
Thanks in advance.
I found that problem. that was in my controller. Exactly in login function. I returened true. Here is the problem. When I return 1 then it worked.

Laravel : Form not submitting but everything looks right?

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.